如何在python中设置套接字的发送缓冲区大小 [英] How to set Send Buffer Size for sockets in python
本文介绍了如何在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
这篇关于如何在python中设置套接字的发送缓冲区大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文