tags:

views:

55

answers:

3

Hi I am using java for socket programming. To create client socket I have to pass IP and port. But I want to create client socket by passing domain name and port whether its possible. My domain name refers to a static address internally. means i want to pass www.xyz.com instead of ip address.

Thanks Sunil Kumar Sahoo

A: 

first u have to get IP Address fo Domain Name...

InetAddress ip = InetAddress.getByName("www.xyz.com");

now var. ip contains the IP address so u can do what ever u want...

Vizay Soni
No you don't. See above.
EJP
A: 

Java.net.Socket has a constructor of the form Socket(String,int), where the first parameter accepts a host name.

Eyal Schneider
+2  A: 

Socket has a constructor, which takes a host name:

public Socket(String host, int port)

It will do gethostbyname() resolution for you.

unbeli