public ServerSocket(int port,int backlog)
Creates a server socket, bound to the specified port. A port of 0 creates a socket on any free port.The maximum queue length for incoming connection indications (a request to connect) is set to 50. If a connection indication arrives when the queue is full, the connection is refused. 看了JDK文档,还是不太懂,有谁能讲得明白点吗?
python也有这个属性,假设设backlog=5,而我用>5个client去连接,竟然不报错

解决方案 »

  1.   

    文档不是有这么一句吗:
    If a connection indication arrives when the queue is full, the connection is refused. 
    程序是不会报错,只是ServerSocket拒绝该连接。
      

  2.   

    backlog指定连接请求队列的长度,但是一旦连接被accept了,就会从该队列中移除。
    backlog并不是该服务器能同时支持的连接数。
    所以只有你不accept去测试才能看到连接被拒绝。
    参见
    http://expert.51cto.com/art/200702/40196.htm
      

  3.   

    backlog指定连接请求队列的长度,但是一旦连接被accept了,就会从该队列中移除。
      

  4.   

    还是要耐心点去读文档啊, 这个不就跟多线程是一样的故事, 你的线程池里面只有三个线程,  现在5个线程同时要来了, 只有三个线程的空间, 那么肯定有人在外等候阿,  backlog你可以理解成线程池中线程的数量!