Set local bind address for client socket in java -


i have multiple nic (network interfaces) installed on server. possible me set default local bind address existing client sockets in java?

it possible programmatically through method:

new socket(inetaddress address, int port, inetaddress localaddr, int localport) 

problem don't have access socketfactory cannot specify localaddr value.

the documentation of abstract socketfactory.createsocket() method speak of in question, points constructor offers need;

 public socket.socket(inetaddress address,      int port,      inetaddress localaddr,      int localport)          throws ioexception 

docs found here


if need change localaddress of existing socket should use bind(socketaddress bindpoint) method, throw ioexception if socket bound.

you should pass inetsocketaddress method socketaddress abstract.


if having trouble finding internal ip addresses of each of interfaces this guide explains how retrieve collection of them.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -