How to set Send Buffer Size for sockets in python

。_饼干妹妹 提交于 2019-12-03 18:03:16

问题


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.


回答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




回答2:


You can use socket.setsockopt():

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, size)


来源:https://stackoverflow.com/questions/30888397/how-to-set-send-buffer-size-for-sockets-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!