简体   繁体   English

用于本地IPC的POSIX消息队列或unix域套接字

[英]POSIX message queues or unix domain sockets for local IPC

I need to setup local IPC between client and server. 我需要在客户端和服务器之间设置本地IPC。 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). 从命令发送的数据很小,但服务器发送给命令的数据很大(~11Mb)。 The existing design in windows sends the data in chunks of 65 Kilobytes using named pipes. Windows中的现有设计使用命名管道以65千字节的块发送数据。 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. 我遗漏了FIFO,因为来自多个进程的数据可以交错为大小超过4096字节的消息。 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? 考虑以下两个标准,这是一个更好的选择,POSIX消息队列或unix域套接字?

  1. size(65K) of the message 消息的大小(65K)
  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 Chandra 此致,Rohini Chandra

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. 使用bind在服务器上设置套接字,然后当每个客户端连接到它时,服务器可以分叉以单独处理每个客户端,或使用select来处理客户端。 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);
    }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM