Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to specify socket buffer size/length?

Status
Not open for further replies.

phn737

Technical User
Nov 4, 2002
31
0
0
US
i am openning a file and printing it to a socket. what i want to do is to be able to control the chunk size of the packet being sent (ie. 128K or 512K or 1024K etc...), how can i do this? thx
 
Somebody once told me that one TCP packet can be a maximum of 1024 bytes... so that might be your answer right there. You'd have to send it in multiple packets in that case.
 
anyone else have any suggestion? Kirsle comment seems incorrect:
he maximum packet size (also called the MTU, or Maximum Transmission Unit) and default packet size can vary depending on the media. For ethernet (LAN), the max packet size is 1500 octets. For dialup, it is 576 octets. For token ring and FDDI, it is 4096 octets.

currently i'm trying to read the buffer with smaller size but this is not the same as sending a small packet to the host, as my timimg result shows same throughtput time regardless of read buffer size. I am expecting a longer transmission time if the packet chunk size/buffer is smaller ie 128k vs 1024k...
...
while ( read( OF, $buffer, $readBufferSz ) ) {
print $socket $buffer;
...
 
The 1500 mtu is transparent to you.

If you want to break it up, you do something like this
print $socket,substr($buffer,0,511);
print $socket,substr($buffer,512,512);
etc.

Sending a "\n" forces a sync.

On the other side, the receive in the event of a 1500+ size, it has to be in a loop to get all the data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top