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

前端 未结 2 1494
梦如初夏
梦如初夏 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条回答
  • 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.

    0 讨论(0)
  • 2020-12-18 16:30

    The image is very small but on closer investigation you have

    • two Java processes
    • the first process has a connection to itself. There is a connection for each end, port 52209 and 52210.
    • it also has a connection from the second process on port 1001.
    • the second process is the client you are running with one connection to port 1001
    0 讨论(0)
提交回复
热议问题