Data transfer progress
Hi
When sending a large chunk of data through a socket how can I keep track of how many bytes have been sent already.
July 02, 2002 09:58 AM
If you''re using sockets...
By monitoring the return values of the send and/or recv functions. They return the number of bytes sent or received in each call respectively, or an error (or a disconenction in the case of recv)
By monitoring the return values of the send and/or recv functions. They return the number of bytes sent or received in each call respectively, or an error (or a disconenction in the case of recv)
Thanks for the replay
But the send function will not return until it finish sending the entire file, what I want is for instance if I’m sending a large file (say 100 MB for example)which will take about 2 minutes on my home network how can I keep track of how man bytes were send each 10 seconds for example.
But the send function will not return until it finish sending the entire file, what I want is for instance if I’m sending a large file (say 100 MB for example)which will take about 2 minutes on my home network how can I keep track of how man bytes were send each 10 seconds for example.
Hmmm. try breaking the file up into smaller chunks (~4k is a good size)... Then you can know how many chunks you made, the size of each chunk, and can report the statistics because the send()/recv() calls will return for each small send. You will have to reassemble the data on the other end also.
July 02, 2002 08:44 PM
If you set the socket to non-blocking it will only send as much data as it can fit into the OS''s send buffer, and then it will return immediately.
Not sure what sort of protocol you are using, but it is definately a good idea to break your data into distinct packets. 512 byte buffers is a good choice of size. As mentioned above you will have to implement a way to put the data together on the other end...which will involve numbering the packets and using headers and anticipating all sorts of errors, including lost packets, "lost" packets which are actually just very late arriving unexpectedly, prevention of packet number looping, as well as delivery verification so you can resend packets that do not arrive....
I suggest either picking up a good book on networking, taking a class, or browsing the web for good tutorials!
If speed is not incredibly important you can implement a TCP protocol which guarantees delivery but dividing the info up is still a good idea.
I suggest either picking up a good book on networking, taking a class, or browsing the web for good tutorials!
If speed is not incredibly important you can implement a TCP protocol which guarantees delivery but dividing the info up is still a good idea.
Thanks guys I''ve got the idea. But why make the parts so small for instance why not divide the file to 10 parts and increment the progress bar 10% after sending each part.
You could break the file into 10 chunks, but the chance of packets getting dropped or mangled on the net increase with size, so it will probably transfer faster by sending smaller chunks. Of course for a large file, you wouldn''t get progress updates very often if you only have ticks at 10%.
Ok but should I use a single socket for sending all chunks or is it better to use more than one socket.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement