Create InetAddress from a String.

Discussion in 'Java' started by jseidelREMOVECAPS@maine.rr.com, Apr 29, 2005.

  1. Guest

    I need to create a socket connection to a site.

    String name = "elektra.usm.com"
    socket sock = new socket( name, port );

    This wont work because the name isn't an ip address. I need to create
    an InetAddress from it. How do I do that?

    Jerry
     
    , Apr 29, 2005
    #1
    1. Advertising

  2. klaus zerwes Guest

    schrieb:
    > I need to create a socket connection to a site.
    >
    > String name = "elektra.usm.com"
    > socket sock = new socket( name, port );
    >
    > This wont work because the name isn't an ip address. I need to create
    > an InetAddress from it. How do I do that?
    >
    > Jerry


    java.net
    Class InetAddress
     
    klaus zerwes, Apr 29, 2005
    #2
    1. Advertising

  3. Ross Bamford Guest

    On Fri, 2005-04-29 at 17:53 +0000, wrote:
    > I need to create a socket connection to a site.
    >
    > String name = "elektra.usm.com"
    > socket sock = new socket( name, port );
    >
    > This wont work because the name isn't an ip address. I need to create
    > an InetAddress from it. How do I do that?
    >
    > Jerry


    For example:

    import java.net.InetAddress;
    import java.net.UnknownHostException;

    try {
    InetAddress in = InetAddress.getByName("www.somewhere.com");
    } catch (UnknownHostException e) {
    // .. whatever
    }

    Ross

    --
    [Ross A. Bamford] [ross AT the.website.domain]
    Roscopeco Open Tech ++ Open Source + Java + Apache + CMF
    http://www.roscopec0.f9.co.uk/ + in
     
    Ross Bamford, Apr 30, 2005
    #3
  4. On Fri, 29 Apr 2005 17:53:04 GMT, wrote:
    > I need to create a socket connection to a site.
    >
    > String name = "elektra.usm.com"
    > socket sock = new socket( name, port );
    >
    > This wont work because the name isn't an ip address.


    Yes it will. The Socket constructor doesn't require an ip address, it
    will gladly accept a hostname.

    /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, Apr 30, 2005
    #4
  5. Guest

    Thank you

    On Sat, 30 Apr 2005 00:08:03 +0100, Ross Bamford <>
    wrote:

    >On Fri, 2005-04-29 at 17:53 +0000, wrote:
    >> I need to create a socket connection to a site.
    >>
    >> String name = "elektra.usm.com"
    >> socket sock = new socket( name, port );
    >>
    >> This wont work because the name isn't an ip address. I need to create
    >> an InetAddress from it. How do I do that?
    >>
    >> Jerry

    >
    >For example:
    >
    >import java.net.InetAddress;
    >import java.net.UnknownHostException;
    >
    >try {
    > InetAddress in = InetAddress.getByName("www.somewhere.com");
    >} catch (UnknownHostException e) {
    > // .. whatever
    >}
    >
    >Ross
     
    , Apr 30, 2005
    #5
    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. C
    Replies:
    1
    Views:
    842
  2. vertigo

    IP: long-> InetAddress

    vertigo, May 2, 2004, in forum: Java
    Replies:
    2
    Views:
    4,455
    Roedy Green
    May 3, 2004
  3. Madhur Ahuja
    Replies:
    1
    Views:
    749
    Paul Lutus
    Aug 29, 2004
  4. Linus

    InetAddress

    Linus, Jan 28, 2005, in forum: Java
    Replies:
    5
    Views:
    12,872
    Linus
    Jan 31, 2005
  5. Replies:
    0
    Views:
    4,629
Loading...

Share This Page