Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert String IP to InetAddress

807603Nov 20 2007 — edited Nov 20 2007
Hey guys,

I'm using sockets and need to make a new Socket which connects to a ServerSocket at a certain IP.

Socket client = new Socket(hostIp, hostPort, localIp, localPort);

The local IP I can find by using System.net.InetAddress.getLocalHost(), but for the host IP I need to use a String address and convert it to an InetAddress object. Is there any way to do this?

Also:

The server-side of my application will be running on my computer using the ServerSocket object, so I need to find my IP to use.

The problem is that I'm using a router, so when I use ipconfig in command prompt it brings up the IP of my router. I used this to access my router settings through my browser and found another IP there. Is this the IP of my modem, or my computer, or (as someone told me) possibly the IP of the computer the network was set up on (not mine).

I'm confused!

Thanks guys.

Edited by: Nienna on Nov 20, 2007 8:33 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 18 2007
Added on Nov 20 2007
5 comments
1,833 views