How to set send buffer size for sockets in python

I have a client socket on my server and I want to install Send buffer sizefor the socket in the same way as I installed Receive buffer size. Any idea on how I can install it? Because when sending huge data, the connector is disconnected.

+4
source share
2 answers

Use socket.setsockopt()and SO_SNDBUF:

socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, <value>)      

Where <value>is the size of the buffer you want to set as Python int.

Example:

socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 8192)  # Buffer size 8192

See: setsockopt

+2
source

you can use socket.setsockopt ()

s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)

s.setsockopt (socket.SOL_SOCKET, socket.SO_SNDBUF, size)

+3

All Articles