Reputation: 4545
a typical socket program example would be like this:
while(1){
data = socket.recv()
//do some work
}
since you don't know when package arrive,it must block to wait until get some data from the listening port,suppose if the program start a heavy work after received the command from another side,during the work , another package arrived,but because at that moment you are doing the work,you are not listening the port, you might missed the package ,no matter how fast you handle the work.
so how does the socket work to handle all the data without any lost?
Upvotes: 2
Views: 548
Reputation: 361849
The operating system has a receive buffer which holds packets that have been received from the network but not yet recv()
ed by the application. If that buffer fills up packets will be lost. You don't have to be in a recv()
call when packets arrive, though you should make sure you call it often enough to keep the buffer from overflowing.
Upvotes: 2