How to set Send Buffer Size for sockets in python
19,068
Solution 1
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
Solution 2
You can use socket.setsockopt()
:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, size)
Author by
Biswarup Dass
Updated on July 24, 2022Comments
-
Biswarup Dass almost 2 years
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 setReceive buffer size
.Any idea on how I can set it? Because while sending huge data, the socket disconnects. -
Biswarup Dass almost 9 yearswhat are the arguments for
setsocketopt()
. It says the take 3 arguments. -
James Mills almost 9 yearsSorry I missed an argument! Fixed :)
-
PersianGulf over 4 yearsIt's very good, But how can I read buffer at target? @JamesMills