I assume you are using UDP since you use sendto/recvfrom. Are you sure that the sockets doing the receiving have been opened at the time that the side doing the sending is doing the sendto? For instance, in your last case there, does the client do a sendto then immediately open a new socket in that new thread to try and recvfrom on? And does the server immediately sendto that new socket? If so, you probably have a race condition going on. Could something like this be going on?
1. Client sends packet to server
2. Server receives packet
3. Server sends new packet to new socket on client
4. Client opens new socket and waits for server to sendto it. (Wait a minute, the server has already sent it's packet and since there wasn't a socket here to receive it yet, it was simply lost. We'll be waiting a long time for a packet unless the server is smart and resends it.)
A successful call to sendto just means that the packet was sent from the perspective of the socket doing the sending. UDP does not guarantee that it was actually delivered. Are your sockets all communicating on the same local network, (or better yet, the same machine)? Because UDP is unreliable, you could just be losing packets. It's not as likely if you are just testing on a local network, but still a possibility. If you cannot afford to lose packets, you will need to either code in some sort of redundancy, some sort of ACK system, or switch to using TCP stream based sockets.
However, if you are seeing this frequently enough and always in the same spot, UDP reliability (or lack thereof) probably isn't the problem. Most likely you have to just restructure the program somehow. Without seeing code or more details as to the layout of your program it's hard to say what else the problem might be, though.
Last edited by deiussum; 10-17-2005 at 10:52 AM.
|