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

发布于 2024-10-09 18:35:07 字数 464 浏览 0 评论 0原文

我需要在客户端和服务器之间设置本地IPC。这是单服务器多客户端的情况,需要双向交换数据。客户端是一个命令,它发送命令选项,服务器获取数据并将其发送给客户端。客户端在控制台上打印从服务器接收到的输出。

命令发送的数据很小,但服务器发送到命令的数据很大(~11Mb)。 Windows 中的现有设计使用命名管道以 65 KB 的块发送数据。服务器需要同时将数据发送到多个命令客户端,因为从不同终端同时执行具有不同选项的命令是很常见的。

我省略了 FIFO,因为来自多个进程的数据可以交织以获取大小大于 4096 字节的消息。如果我错了,请纠正我。

考虑以下两个标准,POSIX 消息队列还是 unix 域套接字哪个是更好的选择?

  1. 来自多个客户端的消息
  2. 数据的大小(65K)不应交错。客户端只能接收发送给该客户端的数据。

如果您需要更多详细信息,请告诉我。

问候, 罗希尼·钱德拉

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 Chandra

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蒲公英的约定 2024-10-16 18:35:07

听起来你想要一个插座。使用bind在服务器上设置套接字,然后当每个客户端连接到它时,服务器可以fork来单独处理每个客户端,或者使用select来处理客户端。分叉通常更简单:

  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);
    }
  }

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);
    }
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文