GeeCON Prague 2014*
The moose likes Sockets and Internet Protocols and the fly likes InetAddress class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "InetAddress class" Watch "InetAddress class" New topic
Author

InetAddress class

Syamsul Hussin
Ranch Hand

Joined: Feb 09, 2003
Posts: 59
hi, I am reading the InetAdress API and I cannot locate the constructor method. how do you construct an object of this class?


----------------------------------<br />SCJP 1.4
Syamsul Hussin
Ranch Hand

Joined: Feb 09, 2003
Posts: 59
lets say if i know the ip address of the host that i want to connect to, and i want to establish a connection using the code:-

and i know which port number i should connect to and the host is listening to that port, can you explain to me how to create the InetAddress object?
Syamsul Hussin
Ranch Hand

Joined: Feb 09, 2003
Posts: 59
or is it that i can just simply put the ip address as the first argument. if i know the ip address of the host as 213.542.543.12 then i could just
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Syamsul,
InetAddress doesn't have any public constructors so you have to use one of the static methods to get an instance of InetAddress for example:


or is it that i can just simply put the ip address as the first argument. if i know the ip address of the host as 213.542.543.12 ...

It has to be a String. So you need to put quotes around it like this:

Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
 
GeeCON Prague 2014
 
subject: InetAddress class