SDL Net - TCP Socket problem

Started by
1 comment, last by hplus0603 17 years, 6 months ago
Hello! I am tring to send a big file over a tcp connection. So i have to split it in about 1200 byte packets. No problem so far. But when I try to recive the packets on the other side he gives me an error because the packets are not yet there. If i put a SDL_Delay(100) infront of the recv command it works fine. But i don't want this because I don'd want so sleep my program. How can I fix this? Jacky2k
Advertisement
you can try using a SDL thread for the function that does the receiving. anyway, you'll need to put that function in sleep that calls itself untill the file is completly received (you'll have to figure out how to do this one, if packages received == total packages, for example).
Why do you need to split it into packets? Just write the serialized file name, the length, and then that many bytes. TCP takes care of the streaming and fragmentation all by itself.

On the other side, if you don't want an EAGAIN when receiving, then use a blocking socket (so recv() will wait), or use select() to test for data.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement