Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Originating connections from multiple IP addresses on same server

Thread view: 
cigusenet@gmail.com - 21 Dec 2005 09:08 GMT
Is there any way to specify which IP address to use when originating a
TCP/IP request?

I have a server with multiple IP addresses and I'd like to use specific
ones to create connections with URLConnection.  I read that this may
not be possible without creating a custom URLStreamHandler, but I'm
hoping there may be an easier way.
Gordon Beaton - 21 Dec 2005 09:36 GMT
> Is there any way to specify which IP address to use when originating
> a TCP/IP request?

Sure, create an unconnected Socket and bind() it to the address of the
interface you want to use before calling connect(). If you only care
about the originating address (not the port number) specify port 0.

> I have a server with multiple IP addresses and I'd like to use
> specific ones to create connections with URLConnection. I read that
> this may not be possible without creating a custom URLStreamHandler,
> but I'm hoping there may be an easier way.

You could use a SocketImplFactory, but that would affect every Socket.
There is a similar factory for URLStreamHandlers, I think that's your
best bet.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Roedy Green - 21 Dec 2005 10:23 GMT
>Is there any way to specify which IP address to use when originating a
>TCP/IP request?
just put in the ip in there where you would otherwise put a DNS.  e.g.
"24.85.32.136"
or
"080:0:0:0:8:800:200C:41FA."
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 21 Dec 2005 10:25 GMT
>Is there any way to specify which IP address to use when originating a
>TCP/IP request?
[quoted text clipped - 3 lines]
>not be possible without creating a custom URLStreamHandler, but I'm
>hoping there may be an easier way.

Another way to do it would be to get the corresponding IP addresses
from the DNS name, pick one yourself and use it.  See
http://mindprod.com/jgloss/ip.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.