recv() and send()
I''m having some problems using recv() and send() functions of winsock library. I have a doubt: If a computer sends two packets (through send() function), and the other computer executes recv() function after the second packet has been sent, will it lose the first packet?? Or are the packets put in a list??
They will end up in winsock''s buffer and the recv will return the first packet that got there.
---Yesterday is history, tomorrow is a mystery, today is a gift and that's why it's called the present.
but what if the second packet is an "error packet"?? In this case, when the server shuts down, it sends a packet to the clients indicating "SOCKET ERROR". Will the packets sent before this ERROR be received??
quote:
Original post by darwintn
but what if the second packet is an "error packet"?? In this case, when the server shuts down, it sends a packet to the clients indicating "SOCKET ERROR". Will the packets sent before this ERROR be received??
I''m not quite sure I understand. Is it sending the error packet to tell the client that it has a problem with the socket? If the socket connection is closed, then the packet will never get to it. Otherwise, it will just queue up in the client''s buffer. If you''re using TCP, the first packet has to be read before the second packet is read. (there are ways around this, but they''re considered more "advanced").
quote:
Original post by darwintn
but what if the second packet is an "error packet"?? In this case, when the server shuts down, it sends a packet to the clients indicating "SOCKET ERROR". Will the packets sent before this ERROR be received??
It depends on how you close the socket. If you just call closesocket(or close depending on the platform), then there's a big chance that the packets will be discared. Instead you should do a graceful disconnect using shutdown. Assuming you are using winsock, the proceduere is the following(from msdn)
1. Call WSAAsyncSelect to register for FD_CLOSE notification.
2. Call shutdown with how=SD_SEND.
3. When FD_CLOSE received, call recv until zero returned, or SOCKET_ERROR.
4. Call closesocket.
Addition(if forgot to say):
You can skip the WSAAsyncSelect part, if you don't use asynchronous sockets.
[edited by - fredizzimo on March 9, 2004 10:16:31 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement