Advertisement

TCP windows threads and lost packages :(

Started by February 24, 2005 07:14 AM
1 comment, last by carl404 19 years, 11 months ago
Hello, I have this nice multiplayer shooter that I'v developed. It suppose run on LAN network so is quite easy. But there is a problem, big and strange! When I run two copies of the game on one PC in two different windows some TCP packets are lost durning switch between windows. When I click on the window bar with a mouse the window stops geting packets from the other one. Well this should be impossible as the TCP is reliable protocol. I guess that this has something to do with windows and threads. Is it possible that system eats window messages ? Carl
The packets don't get lost on the wire in TCP, so it's clearly in your program. Windows doesn't eat messages (normally), but it's possible that your logic makes it not work. Also, of you're using CSocket (the MFC class) in asynchronous mode, there are known bugs in that that may lose notifications at times.

Another possibility is that you're not tokenizing your packets correctly. If you first write 30 bytes, and then write 50 bytes a while later, TCP will happily return back 80 bytes to you the next time you ask to read. Or 70, if 10 didn't make it across yet. You have to write a length before each packet, and then only read that many bytes if you want a stream of packets instead of a stream of bytes.
enum Bool { True, False, FileNotFound };
Advertisement
Wow !!! You were right! The packets are glued together!! Stupid networks :)
Thanks !!!!! :)

This topic is closed to new replies.

Advertisement