user1243746
user1243746

Reputation:

For what is better suited every type of communication in Unix sockets?

I need to build a server using Unix domain sockets, and it looks that there are several options to choose the kind of communication. From man 2 socket:

So, for what is better suited every one of them? (stream, datagram, packet)

Upvotes: 2

Views: 225

Answers (2)

SKi
SKi

Reputation: 8476

It really depends what kind of server you are going to implement.

If message boundaries are important, then SOCK_DGRAM would be the best choice. Because recvfrom/recvmsg/select will return when a complete message is received.

With SOCK_STREAM, message receiving is more tricky: One receiving call may return a partial message, or part of two messages, or several messages... etc.

If message boundaries are not important, then SOCK_STREAM could be the best choice.

SOCK_DGRAM of AF_INET is unreliable UDP. But, in most sytems, SOCK_DGRAM of AF_UNIX is reliable. For example: If queue of receiver is full, sender will be blocked until there is space.

Upvotes: 2

user1285928
user1285928

Reputation: 1476

For TCP -> SOCK_STREAM For UDP -> SOCK_DGRAM

Upvotes: 0

Related Questions