让我感到困惑的是,鉴于套接字是双向的,为什么我不能只在客户端上使用 socket()打开一个套接字,而在服务器上使用 socket()打开一个套接字,然后让它们通过该套接字进行通信一个插座?
What confuses me is that given that sockets are bi-directional, why can't I just open 1 socket with socket() on the client and one on the server and let them communicate over this single socket?
我需要一对插座的常见用例是什么?
What would be a common use case that I would need a pair of sockets?
推荐答案
那我需要一对插座的常见用例是什么?
So what is the common use case that I would need a pair of sockets?
通常,您希望在父子进程之间(或有时在同一进程中的线程之间)进行双向通信.
Typically that you want bidirectional communication between a parent and child process (or sometimes between threads in the same process).
这类似于 pipe 的双向等效项,并且避免为程序内部的某些内容公开 AF_UNIX 路径或任何其他公共可见的地址.
It's like a bidirectional equivalent of pipe, and avoids exposing an AF_UNIX path, or any other publicly-visible address, for something internal to your program.
在此处有一个有效的示例.
更多推荐
当我在AF
发布评论