I have a client socket at my server end and what I want is to set Send buffer size
for the socket just like I set Receive buffer size
.Any idea on how I can set it? Because while sending huge data, the socket disconnects.
If you want see your buffer size in terminal, you can take a look at: /proc/sys/net/ipv4/tcp_rmem (for read) /proc/sys/net/ipv4/tcp_wmem (for write)
A socket has two buffers and some other information associated with it. In the context of sockets programming, a socket is your app's interface to one TCP connection (or UDP flow). Your app doesn't read/write data from/to the network interface card (NIC) directly, it goes through the kernel's network stack.
The size of the send buffer, in bytes. The default value is 8192 bytes.
Change the following set of parameters as needed: /proc/sys/net/core/rmem_default > recv > 124928 > changed to 512000. /proc/sys/net/core/wmem_default > send > 124928 > changed to 512000. /proc/sys/net/core/rmem_max > 124928 > changed to 512000.
Use socket.setsockopt()
and SO_SNDBUF
:
socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, <value>)
Where <value>
is the buffer size you want to set as a Python int
.
Example:
socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 8192) # Buffer size 8192
See: setsockopt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With