Andrew Simpson
Andrew Simpson

Reputation: 7324

Dynamically changing receive buffer size for sockets

i have varying lengths of byte arrays to send from a windows desktop app to a windows service on a server on another PC. I am using Sockets in C#. What i was thinking of doing was working out the number of bytes to send and sending just that info to the server. The server app would adjust the receiving buffer size to accommodate the byte array being send from the client to that server. Is this a poor idea or a good one dynamically changing the receive buffer as the app progresses?

thanks

Upvotes: 0

Views: 2454

Answers (1)

Manoj Pandey
Manoj Pandey

Reputation: 4666

The role of receive side buffer size is to buffer the packets if the application reads data slower than the rate at which network can send. It also helps if the sender sends data in bursts. So, keeping it as a multiple of several MTUs (10/20) should be good enough. If I understood correctly, you are trying to communicate the entire data set (the length of the byte arrays) that you want to send and make the receive side buffer of the same size -- this is certainly not necessary and would be inefficient if the data that you want to send is too large! The reason it would be inefficient is because the OS has to allocate that much memory for the receive buffer.

Upvotes: 1

Related Questions