简体   繁体   中英

Listening to an unlimited number of sockets in python

I was wondering, if I want to listen to each socket that wants to join, what do I need to write inside the sock.listen(?) What number goes there and tells python "I want to listen to everyone" and not to a limited number of sockets. I thought about just putting a large number, but I feel it's not the right answer.

Thanks for the helpers!!

See this answer where John la Rooy says:

The doc say this

socket.listen(backlog) Listen for connections made to the socket. The backlog argument specifies the maximum number of queued connections and should be at least 1; the maximum value is system-dependent (usually 5).

Obviously the system value is more than 5 on your system. I don't see why setting it to a larger number would be a problem. Perhaps some memory is reserved for each queued connection.

My linux man page has this to say

If the backlog argument is greater than the value in /proc/sys/net/core/somaxconn, then it is silently truncated to that value; the default value in this file is 128. In kernels before 2.4.25, this limit was a hard coded value, SOMAXCONN, with the value 128.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM