Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Sending an IP address to a ServerSocket without name resolution?

Reply
Thread Tools

Sending an IP address to a ServerSocket without name resolution?

 
 
nooneinparticular314159@yahoo.com
Guest
Posts: n/a
 
      03-02-2006
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

 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      03-02-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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.


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

/Thomas
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
http://www.uni-giessen.de/faq/archiv....java.gui.faq/
 
Reply With Quote
 
 
 
 
nooneinparticular314159@yahoo.com
Guest
Posts: n/a
 
      03-02-2006
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

 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      03-02-2006
On 2 Mar 2006 04:46:59 -0800, (E-Mail Removed) wrote:
> 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

--
[ 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
 
Reply With Quote
 
nooneinparticular314159@yahoo.com
Guest
Posts: n/a
 
      03-02-2006
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.

 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      03-02-2006
On 2 Mar 2006 06:07:28 -0800, (E-Mail Removed) wrote:
> 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

--
[ 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
peer 2 peer communication without using serversocket in tcp Sudheer Java 2 04-01-2004 09:01 AM
Unusual ServerSocket Behaviour Thomas Hawkins Java 3 01-30-2004 08:44 PM
ServerSocket and ClientSocket - bi-directional Abraham Khalil Java 1 01-26-2004 06:03 AM
Socket / ServerSocket & Remote Disconnection Detecting Jason Teagle Java 12 10-05-2003 10:23 AM
Restrict ports of ServerSocket.accept() sockets Thomas Kuhn Java 4 07-07-2003 08:49 AM



Advertisments