Java nio connection is creating multiple socket level connections, Why?

前端 未结 2 1499
梦如初夏
梦如初夏 2020-12-18 15:33

I have written a simple java nio program like the below

 public static void main(String[] args) throws IOException, InterruptedException {


    InetSocketA         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-18 16:20

    The connection between 1001 and 52211 is being shown twice, once in each direction, as both ports are local.

    A Selector may open another listening socket in case it has to handle sub-selectors so as not to exceed the maximum number of sockets per selector.

    You shouldn't register OP_READ or OP_WRITE until after you've finished the OP_CONNECT pgphasr, when you should also deregister OP_CONNECT. Having all three of those registered at the same time is definitely wrong.

提交回复
热议问题