Create InetAddress from a String.

J

jseidelREMOVECAPS

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
 
K

klaus zerwes

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
 
R

Ross Bamford

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
 
G

Gordon Beaton

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top