Bind an interface in java TCP connection

前端 未结 2 981
梦毁少年i
梦毁少年i 2021-01-02 18:09

I have two interfaces in a solaris host. I would like to initiate two TCP connections to a single TCP server via both interfaces as shown in the diagram. Are there any optio

2条回答
  •  太阳男子
    2021-01-02 18:47

    Do you mean something like this:

    Socket socket1 = new Socket();
    socket1.bind(new InetSocketAddress("10.1.1.1", port));
    socket1.connect(new InetSocketAddress("10.1.3.1", port));
    
    Socket socket2 = new Socket();
    socket2.bind(new InetSocketAddress("10.1.2.1", port));
    socket2.connect(new InetSocketAddress("10.1.3.1", port);
    

提交回复
热议问题