如何在python中设置套接字的发送缓冲区大小
问题描述:
我在服务器端有一个客户端套接字,我想要为套接字设置发送缓冲区大小
,就像我设置 Receive buffer一样大小
。关于如何设置它的任何想法?因为在发送大量数据时,套接字断开了连接。
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.
答
使用 socket.setsockopt()
和 SO_SNDBUF
:
socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, <value>)
其中< value> ;
是要设置为Python int
的缓冲区大小。
Where <value>
is the buffer size you want to set as a Python int
.
示例:
socket.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 8192) # Buffer size 8192
请参阅: setsockopt