简体   繁体   English

Unix 域 SOCK_DGRAM 和 SOCK_SEQPACKET 的区别?

[英]Difference between Unix domain SOCK_DGRAM and SOCK_SEQPACKET?

According to the Linux man pages for Unix sockets, "Valid socket types in the UNIX domain are. . . SOCK_DGRAM, for a datagram-oriented socket that preserves message boundaries (as on most UNIX implementations, UNIX domain datagram sockets are always reliable and don't reorder datagrams); and (since Linux 2.6.4) SOCK_SEQPACKET, for a sequenced-packet socket that is connection-oriented, preserves message boundaries, and delivers messages in the order that they were sent." According to the Linux man pages for Unix sockets, "Valid socket types in the UNIX domain are. . . SOCK_DGRAM, for a datagram-oriented socket that preserves message boundaries (as on most UNIX implementations, UNIX domain datagram sockets are always reliable and don 't reorders datagrams);和(自 Linux 2.6.4 起)SOCK_SEQPACKET,对于面向连接的序列数据包套接字,保留消息边界,并按照消息发送的顺序传递消息。” ( http://man7.org/linux/man-pages/man7/unix.7.html ). http://man7.org/linux/man-pages/man7/unix.7.html )。

I thought "always reliable and don't reorder datagrams" is the same as "delivers messages in the order that they were sent."我认为“始终可靠且不重新排序数据报”与“按照发送顺序传递消息”相同。

What's the practical difference between SOCK_DGRAM and SOCK_SEQPACKET? SOCK_DGRAM 和 SOCK_SEQPACKET 之间的实际区别是什么?

In the context of UNIX domain sockets, the main difference between two is "datagram-oriented" vs "connection-oriented".在 UNIX 域 sockets 的上下文中,两者之间的主要区别是“面向数据报”与“面向连接”。

In case of SOCK_DGRAM you don't create a connection (to a server, for example), you just send packets to the server socket.在 SOCK_DGRAM 的情况下,您不创建连接(例如到服务器),您只需将数据包发送到服务器套接字。 And if server needs to reply, you need to create your own socket, make server aware of this socket and then server can send a reply to it.如果服务器需要回复,您需要创建自己的套接字,让服务器知道这个套接字,然后服务器可以向它发送回复。 Very inconvenient, if you really need a connection, but can be useful when you just need one-way communication, ie to send some notifies.非常不方便,如果您真的需要连接,但当您只需要单向通信时可能很有用,即发送一些通知。

SOCK_SEQPACKET is the way to go, when you need connection-oriented approach. SOCK_SEQPACKET 是 go 的方式,当你需要面向连接的方式时。

The difference is better understood by the help of UDP and TCP.通过 UDP 和 TCP 的帮助可以更好地理解差异。 A protocol like UDP(connection-less) uses SOCK_DGRAM, implementation像 UDP(无连接)这样的协议使用 SOCK_DGRAM, 实现

A protocol like TCP(connection-oriented) uses SOCK_STREAM.像 TCP(面向连接)这样的协议使用 SOCK_STREAM。 However, even SOCK_SEQPACKET can be used.但是,甚至可以使用 SOCK_SEQPACKET。 The difference between the two is very minimal, TCP can be implemented using the latter as well.两者之间的差异非常小,TCP 也可以使用后者来实现。 In fact, SOCK_SEQPACKET is somewhat a hybrid of both.事实上,SOCK_SEQPACKET 在某种程度上是两者的混合体。 STCP is a use case for SOCK_SEQPACKET. STCP 是 SOCK_SEQPACKET 的一个用例。 Explained in this article: http://urchin.earth.li/~twic/Sequenced_Packets_Over_Ordinary_TCP.html本文解释: http://urchin.earth.li/~twic/Sequenced_Packets_Over_Ordinary_TCP.html

Here's a post that has discussed this in detail.这是一篇详细讨论过这个问题的帖子

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

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