Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > InetAddress

Reply
Thread Tools

InetAddress

 
 
Linus
Guest
Posts: n/a
 
      01-28-2005
I don't understand how to set a InetAddress variable with an IP address like

InetAddress ip = 192.168.0.1;

I thik it's some kind of syntax error.
Thanks to everyone who'll help me.

Linus
 
Reply With Quote
 
 
 
 
Antti S. Brax
Guest
Posts: n/a
 
      01-28-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in comp.lang.java.programmer:
> I don't understand how to set a InetAddress variable with an IP address like
>
> InetAddress ip = 192.168.0.1;
>
> I thik it's some kind of syntax error.


There is a fundamental syntax error in your code. It is such an
error, that it might be a better idea for you to start from the
Java tutorial: <http://java.sun.com/docs/books/tutorial/>.

--
Antti S. Brax Rullalautailu pitää lapset poissa ladulta
http://www.iki.fi/asb/ http://www.cs.helsinki.fi/u/abrax/hlb/
"Disconnect this cable to shorten, re-connect to lengthen."
-- Instructions on Logitech's USB mouse extension cord.
 
Reply With Quote
 
 
 
 
Steve Horsley
Guest
Posts: n/a
 
      01-28-2005
Linus wrote:
> I don't understand how to set a InetAddress variable with an IP address like
>
> InetAddress ip = 192.168.0.1;
>
> I thik it's some kind of syntax error.
> Thanks to everyone who'll help me.
>
> Linus


It has no public constructor, so you have to call one of InetAddress's
static factory methods (a method that makes instances of InetAddress).
In this case, I think you want:

InetAddress ia = InetAddress.getByName("192.168.0.1");

Steve
 
Reply With Quote
 
Andrew Tyson
Guest
Posts: n/a
 
      01-29-2005
Linus wrote:
> InetAddress ip = 192.168.0.1;


A little off topic but making this syntax legal would be a nice
enhancement of the JDK 1.5 autoboxing facility IMHO ....

 
Reply With Quote
 
Nick
Guest
Posts: n/a
 
      01-29-2005
Linus wrote:
> I don't understand how to set a InetAddress variable with an IP address like
>
> InetAddress ip = 192.168.0.1;
>
> I thik it's some kind of syntax error.
> Thanks to everyone who'll help me.
>
> Linus

The InetAddress class is a little unusual in that it doesn't have any
public constructors. Instead you pass the host name or string format of
the dotted quad address to the static InetAddress.getByName() method
like this:

try {
InetAddress utopia = InetAddress.getByName("utopia.poly.edu");
InetAddress duke = InetAddress.getByName("128.238.2.92");
}
catch (UnknownHostException ex) {
System.err.println(ex);
}

-Nick
 
Reply With Quote
 
Linus
Guest
Posts: n/a
 
      01-31-2005
Thank you to everyone, you have resolved my problem.

Linus

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
InetAddress question Rhino Java 1 02-26-2005 04:52 PM
InetAddress isReachable() andy.dreistadt@gmail.com Java 0 02-10-2005 03:07 PM
performing reverse DNS lookup with InetAddress Madhur Ahuja Java 1 08-29-2004 07:57 AM
IP: long-> InetAddress vertigo Java 2 05-02-2004 11:59 PM
Solaris 9 and InetAddress with IP hostname C Java 1 09-16-2003 12:27 PM



Advertisments