I'm developping a C application that make extensive use of sockets.

My doubt is: Does every socket that I create have its own buffers to send and/or receive messages from other sockets?

In other words, can sockets be influenced by messages exchange erroneously?

By erroneously I mean that messages sent to one socket can be "leaked" to another socket without having written (and be it by mistake) program code that would explicitly transmit messages from the "intended" receiver to another socket.

  • 1
    Your question is hard to understand. Are you asking "can messages on one socket cross-talk/interfere to other sockets?" ? Commented Sep 17, 2020 at 21:04
  • Exactly @ctrl-alt-delor
    – j0s3
    Commented Sep 18, 2020 at 7:54
  • edit the question to make it clear. If you make people read all the comments, then you won't get a good answer. Commented Sep 18, 2020 at 15:35

2 Answers 2


Does every socket that I create have its own buffers to send and/or receive messages from other sockets?


Otherwise the sockets API would be essentially unusable, for exactly the reason you suggest.

Just to clarify, since you didn't specify what type of socket you're using:

  • each TCP / streams socket will have its own unique send & receive buffers.

    These buffers are necessary for it to handle resending, ack management, reassembly etc. in the background.

  • each UDP / datagram socket will have its own receive buffer, but not necessarily a unique & persistent send buffer.

    It doesn't have any retransmit logic that would require a persistent send buffer.

  • a socketpair may share a single buffer between both sockets (or a single buffer in each direction)

    For comparison a pipe (which isn't identical to a socket) would usually have just one buffer shared between both file descriptors, since it is unidirectional.


Yes that is what TCP and UDP is for: to multiplex the network. To make many virtual networks.

IP just sends packets. They can be anything, they just go from this machine to that one. No channels, no re-sends, just try to deliver it. This is what the internet works on.

TCP and UDP add channels to this (sockets). TCP adds re-sends. Can it go wrong:

  • Data corruption should be detected with checksums. Are the check sums strong enough (for TCP probably not, but the hardware layer has good checksums).
  • In software you could write a bug and send/receive to the wrong channel/socket.
  • However you can not send/receive on a socket that your process did not open (unless you are passed a file handle by another process).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .