Advertisement

Receiving a file?

Started by July 18, 2004 10:26 AM
6 comments, last by cbenoi1 20 years, 6 months ago
Hello :) I m still trying to send a large file (about 25mb) over a non blocking winsock socket connection.. I have managed to send a small file (12 bytes) but I don't know how to spilt and send a large file as 1024 byte chunks "syncronized" with the reciever.. (Both the client and server already know the size of the file..) I'm thinking something like this.. //Client - Send Create a loop for reading the large file piece by piece into 1024 byte chunks and sending the chunks.. Will this loop crash the receiving server? Since it will feed it a lot of data when looping? Or is there a way around this? //Server – Recv I don’t how to set up "FD_READ" to receive a larger file in chunks and put them into a file piece by piece.. All help appreciated!
The loop won't crash anything. If the receiver doesn't read the data quickly enough then it will most likely get buffered somewhere along the way. Eventually the connection might be dropped but nothing should crash. I'd normally wait for confirmation of a successful send before sending the subsequent piece of data anyway. The receiver should just loop, reading as much as it can each time and appending the data to the designated storage area. If the file is too big to hold in memory then maybe a memory-mapped file is what you need at the receiving end.
Advertisement
Correct.

One solution is file-mapping. Simply traverse the pointer.

Kuphryn
If you're using TCP, then just write on one end, and read on the other.

If the other end doesn't read fast enough, in the end, the send on the sending end will block or, in case of non-blocking, won't send any bytes until some more buffering is made available by the other end reading again, so make sure to check the return values of your send functions!
enum Bool { True, False, FileNotFound };
True, TCP/IP is quite wonderful with the reliability it provide ::)

A simple way would be, let's first have server and client get to know the details of the file and the size of the chunks to be transffred.

Then the client can request for the first chunk and the server will send it.Once the client recives it and does what ever that has to be done with that info, the client can request for the next chunk.

This way the client can even come back after disconnecting and continue from where it wants.

So lets say the size of the file is 10 mb,and one chunk can be 1 mb.So the first chunk is 0 - 1 mb,second chunck is 1 - 2 mb...

[CREDITS:kuphryn,Kylotan]

Helps?
______________________________________________________________________________________________________
[AirBash.com]
Thank you for all your help :)
I have managed to send and receive a 145MB mpeg movie now.. Very cool!

I have checked the size of the movie received and it is correct. But when I play the two movies at the same time there seem to be small errors in the received movie, the picture freezes for a few ms and then starts to run smooth again..

Any suggestions why the received data is a little different?


Advertisement
Cool!!!,

About the file being recive diffrently,well first you better write a simple program to analyse which bytes are diffrent.That should give you some directions as to what went wrong.

Try that out,ok?
______________________________________________________________________________________________________
[AirBash.com]
> trying to send a large file (about 25mb)
> over a non blocking winsock socket connection.

TransmitFile() / TransmitPackets(). Those calls were designed specifically for high-performance web servers. The socket needs to be in overlapped mode; it's even more performant through the use of IOCP.

-cb

This topic is closed to new replies.

Advertisement