Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
549 views
in Technique[技术] by (71.8m points)

c - send() before recv()

i have two projects: one is a client and one is a server. lets say the server as to send 2 messages one after the other to the client. the client code is like this:

while(1)
{
      recv(acceptedStr, socket);
      printf("%s
, acceptedStr);
      *other code lines*
}

while the server code is like this:

while(1)
    {
          send(socket, "First String");
          send(socket, "Second String");
          *other code lines*
     }

if there is no TIME_OUT for the second send, will the recv of the client get "Second String"? or does he have to make sure that he is in a recv before the server send?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

No, the receiving end does not need to have an recv active for the send to work.

Once a connection is established, the data is buffered by the OS network stack. And recv will succeed once data has arrived and send will succeed if the data was delivered to the network stack of the receiver.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...