Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind an interface in java TCP connection

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 options in Java to bind the interface to the TCP socket to override the local routing table?

I am attaching the network diagram,

network_diagram

I would like to use both the serial links bandwidth to get the data from server. Hence I would like to initiate the connection on both the interfaces.

thanks,

like image 417
Mohan Avatar asked Jul 13 '12 12:07

Mohan


2 Answers

You can use

Socket s = new Socket(hostname, port, localInterface, 0);

However, many OSes do not honour this "hint" and will use the routing table anyway.

like image 73
Peter Lawrey Avatar answered Oct 03 '22 13:10

Peter Lawrey


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);
like image 31
geby Avatar answered Oct 03 '22 14:10

geby