Link to home
Start Free TrialLog in
Avatar of rumi78
rumi78

asked on

jvm default socket address

I jave multiple network interfaces and IPs assigned to my machine.

I would like to tell java virtual machine to use specific address as a source address for every network connection.
There is possibility to define source address using e.g.: Socket(InetAddress address, int port, InetAddress localAddr, int localPort)
but it is no option here, I am obligated to use: Socket(InetAddress address, int port).

The possible solution may consists of:
1. implementation of Socket provider/factory/anything, which will be used iso default sun provider,
2. java -D some parameters
3. some OS tricks

Note: The proxy solution (-DsocksProxyHost) is a workaround, and I will use it if nothing useful is found.

rgds
rumi
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

The factory approach is probably the best
> Note: The proxy solution (-DsocksProxyHost) is a workaround, and I will use it if nothing useful is found.

thats the normal way to handle it. Doesn't cause any problems does it?
just listening :-)
Btw, why you can't use Socket(InetAddress address, int port, InetAddress localAddr, int localPort) ?
Any other solution different from using socksProxyHost will be somekind of proxy.
Did you find some other solution?
Avatar of rumi78
rumi78

ASKER

Dear Valeri,
Why I can not use Socket(InetAddress address, int port, InetAddress localAddr, int  localPort) is not important here.
But If you try a little you can find: when you can not access to source code (db driver, vpn implementation, other libraries you can not, and should not decompile and rebuild to add localAddress).

Dear objects,
Socks solution is a workaround, it is stupid to ask customer to install additional software with your application, because java can not handle it ;)

Dear CEHJ,
Are you able to provide example implementation ? Could you point me some example of socket provider with minimal extension solution ?
Is the implementation  independent on jvm machine version ( os related differences, future compatibility, etc.) ?

Thank you all.
rgds
rumi
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)