I am writing the second part of my app that will transfer images thru net. At present time I wrote an server and a client program. The server waits for client to connect and then start capturing a frame, from a video for windows source, at every second and send it to the client, with : invoke send,sock_,addr outbuff1,eax,0 where eax is the size of the packet. Tha problem is that : If the connection is fast, I usually have no transfer problems but, if the transfer speed is any slow (in my case I use the microsoft's dial-up server to make a point-to-point connection between 2 computers), the image is divided into 2 or more packets\ and I get loosing the second and the nexts packets, in the client's side. So I do that : I preceed the image packet with the string "INIT", then with 4 bytes (a dword) with the size of the packet (eax), and then send it to the client. In theory I could make 2 or more recv in the client's side, but, for every packet that arrives to client, I get another FD_READ message. I'm going to loose the few hair I have, but could not find how to code the reception in the client's side. Any ideas?? Please Help... thanks
tell me more info, are you sending a packet first off, that has the size of the file ect.? this way you know what is all needed to catch, and each packet could have a DWORD in the first byte of the packet that is not part of the image but would tell you what part of this file it is 1,2,3,4 ect then you could send after awhile a packet back telling your server that you did not get packet such, and such. maybe I am wrong on what you meant, but I still gave this a shot. Zcoder....
No. In the server, I make that : 1 - put the string 'INIT' in the first 4 bytes of my buffer; 2 - put the lenght of the image data in the next 4 bytes (a dword with mov ,eax; 3 - put the image data in the buffer from the 9th byte on; so we have : XXXX XXXX XXXXXXXXXXXXXXXX INIT size image data...... when this is ready, I send all packet with: invoke send,sock_,addr outbuff1,eax,0 where outbuff1 is the buffer with all the data and size and the INII string, and eax is the size of everithing. Now, the problem is that : If the packet has more than 3.8 Kbytes (more or less) the client receive with several FD_READ posts. In the first FD_READ post, I read the header and some of the image data, then If the start of the buffer is the string INIT, then I know that this is the first part of the image data, so I read it's size. Then I compare this size with the size of the image data I just received. If they match, then I continue and process the image data, if not, I just put this partial image data in a buffer, waiting for a new FD_READ to occours. Whent this happen, I read again to see if there is a header with the string INIT, if not, I just append the data to the end of my image data and compares again to see if the size of all this image buffer is the same of that size in the original header, and if it is the same, I process the image, if not, I have to wait for another FD_READ post, and if in this nw FD_READ post there is the INIT string and I didn't finished the previous image, then I had some kind of error, so I restart again listening, and so on... This is the idea, but till now, I didn't get how to make it work... I feel myself stupid, but I am learning. If you can help me, thank you very much. This program will be sent to Iczelion to make it available to everybody. thanks
Checking for the string "INIT" to see if it's the start of a new image is a bad method, because of these reasons:
What if the string "INIT" occurs in the image data ?
What if the end of one image and the start of a new image are sent in one package, like this:
IMAGE1_IMAGE1_IMAGE1_IMAGE1 INIT XXXX IMAGE2_IMAGE2.
Then there won't be a INIT at the beginning of the package
Instead, forget about the INIT string and just send the size, with the data following. Just add data to a buffer until you've received the given size. Then read the next size, and so on. If you want some error checking, add a checksum of a full image to the end of start of the data.