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 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
Post a Comment