Hey guys I have a general network programming issue I hope someone here can help with. I'm familiar with win32 general API programming as well as the socket APIs. My problem is dealing with multiple simultaneous file transfers being sent in a way my code doesn't expect.
Here is the overall idea:
Server initiates a file transfer via "sendfile" command and basically my client acknowledges and parses the data in the same recv loop as used for the communications channel.
Server sends over socket "sendfile:filename:size" followed by the actual file in a format like this:
"sendfile:[filedata]"
"sendfile:[filedata]" until the file is sent in its entirety (2048 byte buffer)
The client simply:
while(connected)
{
if(strcmp(recvbuffer,"sendfile:",9)==0) { handlefile(recvbuffer[9],len-9);
else if() ; blah blah
}
This works perfectly however sometimes the data will be received by the client without the initial "sendfile:" part so my parsing code will miss some data and the file becomes corrupt.
My issue is that sometimes the underlying network will send half the data followed by the other half but my code expects each recv buffer to be preceeded by the string indicating a transfer is taking place.
I imagine file transfer is a very well understood topic but I'm not sure how to solve this problem. Any ideas/suggestions are greatly appreciated!
Thanks again.