Need help on SDLNet_TCP_Recv()

Hi.

I am writting a programming that receives data with a size of 5000 by using
SDLNet_TCP_Recv(). But most of the time I found the data received is incomplete.

The recv() function from <sys/socket.h> is able to wait for all the data to be
totally transferred, by flag MSG_WAITALL.

I want to do the same thing with SDLNet_TCP_Recv(), but found not hints.

Please help me!

Yu

A packet size of 5000 is likely to be split up by routers and such along
the way. I do not think that the SDLNet TCP layer recombines packets that
have been split up in this way. What you may consider doing is have the
first byte of the packet be it’s intended length, then keep calling recv
and decrementing a length variable by the size of the packet that came in
until it is 0, then merge all the packets back together and do it again.

  • Will> Hi.

I am writting a programming that receives data with a size of 5000 by
using SDLNet_TCP_Recv(). But most of the time I found the data received
is incomplete.

The recv() function from <sys/socket.h> is able to wait for all the
data to be totally transferred, by flag MSG_WAITALL.

I want to do the same thing with SDLNet_TCP_Recv(), but found not
hints.

Please help me!

Yu


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Can you give me a sample code of it? Mine seems doesn’t work. It only work if
there is a printf() in the loop, or it will just stop there doing nothing.

Yu Wang wrote:

Can you give me a sample code of it?

1541.org -> SNL

it is a standalone network library, without SDL_Net, but it uses this
packet length header protokoll.

Mine seems doesn’t work. It only
work if there is a printf() in the loop, or it will just stop there
doing nothing.

printf serializes your code. maybe it is a race condition, if you are
using threads.

clemens