napsy
February 14th, 2009, 11:55 AM
Hello.
I've programmed in network sockets for some time now but never figured it out an efficient way to send large data through sockets.
For example, I have a 2 MB data that I want to send to a client. The data contains multiple small data that I later parse and separate. Because recv() must have a fixed length and the receiver buffer is limited, there's no guarantee that all data is sent with one single send() call. There's a trick to create a loop but the data is so dynamic and the server has threads that send different data to s single socket connection. I solved this by fragmenting every data buffer to 1kb smaller fragments and always sending them together with a header attached that tells what data is it and what's the data's total length.
Now I'm asking is there another way to send large dynamic data that needs to be separated
I've programmed in network sockets for some time now but never figured it out an efficient way to send large data through sockets.
For example, I have a 2 MB data that I want to send to a client. The data contains multiple small data that I later parse and separate. Because recv() must have a fixed length and the receiver buffer is limited, there's no guarantee that all data is sent with one single send() call. There's a trick to create a loop but the data is so dynamic and the server has threads that send different data to s single socket connection. I solved this by fragmenting every data buffer to 1kb smaller fragments and always sending them together with a header attached that tells what data is it and what's the data's total length.
Now I'm asking is there another way to send large dynamic data that needs to be separated