Weird behavior of send() and recv()
<p>SORRY FOR BAD ENGLISH</p>

<p>Why if I have two <strong><code>send()</code></strong>-s on the server, and two <strong><code>recv()</code></strong>-s on the client, sometimes the first <code>recv()</code> will get the content of the 2nd <code>send()</code> from the server, without taking just the content of the first one and let the other <code>recv()</code> to take the "due and proper" content of the other <code>send()</code>?</p>

<p>How can I get this work in an other way?</p>

<p>Most probably you use SOCK_STREAM type socket. This is a TCP socket and that means that you push data to one side and it gets from the other side in the same order and without missing chunks, but there are no delimiters. So <code>send()</code> just sends data and <code>recv()</code> receives all the data available to the current moment.</p>

<p>You can use SOCK_DGRAM and then UDP will be used. But in such case every <code>send()</code> will send a datagram and <code>recv()</code> will receive it. But you are not guaranteed that your datagrams will not be shuffled or lost, so you will have to deal with such problems yourself. There is also a limit on maximal datagram size.</p>

<p>Or you can stick to TCP connection but then you have to send delimiters yourself.</p>

python