The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Kucki on December 20, 2006, 09:39:52 PM

Title: Recv
Post by: Kucki on December 20, 2006, 09:39:52 PM
Hello,

In my Programm, a Win32 Application, I use Winsocks to send a File from a Server(own coded) to a Client(own coded).
It works good when the file, which is sent, ist very small. But if i send a bigger File (for example: Filesize: 8000 bytes) ist didn't work.
I found the reason why.
The Recv function doesn't wait until it is complete recved.
It only recved 1024 first bytes(when i call "recv" again it recved the rest).
But i don't want to split this File.

Have you any Suggestions, how i can say "recv",that it should wait until he recved all?

P.S. Hope you can understand my English.

Title: Re: Recv
Post by: PBrennick on December 20, 2006, 09:54:06 PM
Kucki,
If you do not mind doing so, it might be helpful if you attach the project. What is happening is you are only sending one packet. Chances are, you already know the solution, you need to create a loop and continue sending packets until you are done.

Paul
Title: Re: Recv
Post by: u on December 20, 2006, 11:54:00 PM
Make your socket "blocking", after you read these tutorials http://www.madwizard.org/view.php?page=tutorials.contents
Title: Re: Recv
Post by: Tedd on December 21, 2006, 04:56:33 PM
The file WILL be 'split' - this is how the internet works - you can not avoid this.
It is not difficult to allocate a large block of memory to save the file into (which you would do if you receive it all in one piece) and then recv the first piece at the start of this memory, then recv the next piece and save it directly after the previous piece, and recv again..... until you have received all of the file -- it will be stored as 'one piece.'

Winsock does buffer the pieces, so you 'could' wait a few minutes and then do the recv, hoping all the pieces have arrived by that time, but this is still not guaranteed to work every time - data sent over the network will be fragmented, deal with it :P