Kushal Kumaran 在 2021年2月17日 星期三下午12:11:04 [UTC+8] 的信中寫道: > On Tue, Feb 16 2021 at 07:24:30 PM, Jach Feng <jf...@ms4.hinet.net> wrote: > > I am experimenting with multithreading-socket these days. I build a > > server to handle each client in a separate thread. All are running on > > my local PC. It works fine except the listen() method. > > > > I set listen(2) and expect to see "error" when more clients than "the > > maximum number of queued connections" trying to connect the > > server. But, no error!! Even 4 clients can run normally without > > problem. > > > > Am I misunderstanding the meaning of this argument? > > > The argument to listen specifies the maximum number of "outstanding" > connection requests. These are connections for which the TCP handshake > has completed, but for which the application has not called accept. > With your multi-threaded application, I assume each new connection > request gets picked up immediately by an accept call, so the queue does > not generally grow. > > If you want a limit on the number of concurrent clients you want to > handle, you'll have to implement that yourself. If you're using the > threading module, threading.Semaphore will let you implement a simple > system. > > -- > regards, > kushal
You are right! I do misunderstand its meaning:-( After the server accepts the 1st connection and paused temperately, I saw the 2nd and 3rd connection is in pending, and the 4th one was rejected immediately. Thank you (and Jason) for clarifying this mystery:-) --Jach -- https://mail.python.org/mailman/listinfo/python-list