how many bytes to write/read

Hi,
I want to send files to a server (that I’m writing). How many bytes at a time should I read from the file and write to the socket? Is there a standard amount that most people are using?

Thank you!

Joseph,

What platform is the client and server? I assume TCP so you are going to have TCP MSS segment your data. The OS’s negotiate this during the TCP three way handshake.

Hi Mike,

Yes it’s tcp sockets I’m working with. I’m developing for Mac. I googled mms segments and I don’t understand. Is it my responsibility to segment it? It seems like I would have to since the files are 2-3 mbs. I wrote a FTP upload app many years ago and I divided the file up into segments but don’t recall what size the segments were.

The socket should handle everything for you.

Hi Tim,
So I can open the file and write it out on the socket in its entirety?

[quote=53316:@Joseph Morgan]Hi Tim,
So I can open the file and write it out on the socket in its entirety?[/quote]

This should work, though it will use more memory (a minimum of 2x the number of bytes in the file).

Which shouldn’t be a problem with only a few megabytes in the file.

From personal experience transferring multi-megabyte files over relatively slow connections (600k aDSL in NZ), I can say that you may easily push the TCP Socket to the wall. It will simply stop transmitting data. After a lot of experimenting I found that I could send 256k packets with a MD5 checksum requiring an acknowledgment from the receiver and achieve a good result. I also found that I could run 6 of these sockets in parallel and max out a 100Mb circuit between two Xojo apps on different hardware over a Gigabit switch. I suspect I could have gotten faster, but the bottleneck became the HDD’s write speed.

This is on Windows.

Joseph,

No the Operating systems handle the TCP MSS size and hopefully neither will use PMTUD :slight_smile: