当我在AF

编程入门 行业动态 更新时间:2024-10-25 17:17:07
本文介绍了当我在AF_UNIX中使用socket()时,为什么需要socketpair()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

让我感到困惑的是,鉴于套接字是双向的,为什么我不能只在客户端上使用 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

本文发布于:2023-10-07 15:38:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469796.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我在   AF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!