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 / March 2006

Tip: Looking for answers? Try searching our database.

Sending an IP address to a ServerSocket without name resolution?

Thread view: 
nooneinparticular314159@yahoo.com - 02 Mar 2006 12:18 GMT
I am writing a simulation which needs to maintain a table that maps
host names to IP addresses.  Because I will be connecting to simulated
hosts, the hostnames do not exist in DNS.  I will, however, be
connecting to real hosts.  I need a way to create a ServerSocket that
connects to my choice of IP address.  But ServerSocket only takes
InetAddress objects, and those don't provide a way to set the IP
address.  Is there a way to do this?

Thanks,
Michael
Thomas Weidenfeller - 02 Mar 2006 12:23 GMT
> I am writing a simulation which needs to maintain a table that maps
> host names to IP addresses.  Because I will be connecting to simulated
[quoted text clipped - 3 lines]
> InetAddress objects, and those don't provide a way to set the IP
> address.

Wrong. Please see the API documentation of InetAddress.getByAddress(byte[]).

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

nooneinparticular314159@yahoo.com - 02 Mar 2006 12:46 GMT
Thanks!  I didn't see that.  So do I need to create a string:

a.b.c.d

including the "."s, and convert that into a Byte Array?  Or does it
expect the IP without the .'s?

Thanks,
Michael
Gordon Beaton - 02 Mar 2006 12:49 GMT
> Thanks!  I didn't see that.  So do I need to create a string:
>
> a.b.c.d
>
> including the "."s, and convert that into a Byte Array? Or does it
> expect the IP without the .'s?

Just create a string containing the IP address:

 Socket s = new Socket("192.168.141.29", 80);

/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

nooneinparticular314159@yahoo.com - 02 Mar 2006 14:07 GMT
Hi, Gordon.  I tried a version of this earlier.  It didn't work - I
think it tried to use the IP address in quotes as a hostname, and
failed to look up the hostname, of course.
Gordon Beaton - 02 Mar 2006 16:24 GMT
> Hi, Gordon. I tried a version of this earlier. It didn't work - I
> think it tried to use the IP address in quotes as a hostname, and
> failed to look up the hostname, of course.

The Socket constructor passes the host String to
InetAddress.getByName(), which does not attempt to look up literal IP
addresses. It simply checks that the format is correct before creating
an InetAddress() from the String.

/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



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



©2008 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.