开发者

POSIX message queues or unix domain sockets for local IPC

I need to setup local IPC between client and server. It is a case of single server and multiple clients and data need to be exchanged in both directions. The client is a command which sends the command options and the server fetches the data and sends it to the client. The client prints the output received from server on the console.

The data sent from the command is small but the data sent by the server to the command is huge(~11Mb). The existing design in windows sends the data in chunks of 65 Kilobytes using named pipes. Server need to send the data to multiple command clients simultaneously as it is common to execute commands with different options at the same time from different terminals.

I have left out FIFO since the data from multiple processes can be interleaved for messages of size greater than 4096 bytes. Please correct me if I am wrong.

Considering the below two criteria, which would be a better choice, POSIX message queues or unix domain sockets?

  1. size(65K) of the message
  2. data from multiple clients should not be interleaved. Only data addressed to that client should be received by a client.

Please let me know if you need more details.

Regards, Rohini Chandr开发者_开发技巧a


Sounds like you want a socket. Set up the socket on the server using bind, then when each client connects to it, the server can either fork to handle each client individually, or use select to process the clients. Forking is usually simpler:

  int sock = create and bind the socket to any port

  while (1) {
    int client = accept(sock);
    pid_t pid = fork()
    if (pid == 0) {
       // Handle client command
       exit(0);
    }
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜