Sending an IP address to a ServerSocket without name resolution?

Discussion in 'Java' started by nooneinparticular314159@yahoo.com, Mar 2, 2006.

  1. Guest

    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
     
    , Mar 2, 2006
    #1
    1. Advertising

  2. 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/computer-lang/java/gui/faq
    http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
     
    Thomas Weidenfeller, Mar 2, 2006
    #2
    1. Advertising

  3. Guest

    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
     
    , Mar 2, 2006
    #3
  4. On 2 Mar 2006 04:46:59 -0800, 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
     
    Gordon Beaton, Mar 2, 2006
    #4
  5. Guest

    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.
     
    , Mar 2, 2006
    #5
  6. On 2 Mar 2006 06:07:28 -0800, 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
     
    Gordon Beaton, Mar 2, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew FPGA
    Replies:
    0
    Views:
    979
    Andrew FPGA
    Sep 26, 2005
  2. Replies:
    2
    Views:
    575
    Christopher Reed
    Apr 15, 2006
  3. Thomas Kuhn
    Replies:
    4
    Views:
    922
    Thomas Kuhn
    Jul 7, 2003
  4. Sudheer
    Replies:
    2
    Views:
    1,320
    Roedy Green
    Apr 1, 2004
  5. rocky
    Replies:
    2
    Views:
    326
    rocky
    Jul 7, 2009
Loading...

Share This Page