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.
Asked
Active
Viewed 2.3k times
2 Answers
15
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

Iván Pérez
- 2,278
- 1
- 24
- 49

James Mills
- 18,669
- 3
- 49
- 62
-
what are the arguments for `setsocketopt()`. It says the take 3 arguments. – Biswarup Dass Jun 17 '15 at 10:22
-
Sorry I missed an argument! Fixed :) – James Mills Jun 17 '15 at 10:24
-
It's very good, But how can I read buffer at target? @JamesMills – PersianGulf Sep 12 '19 at 12:10
6
You can use socket.setsockopt()
:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, size)

dzikoysk
- 1,560
- 1
- 15
- 27

arun.rajput
- 127
- 2
- 3