How to get ip address for multiple player game?

as the title said, how can I get the ip address of my computer by using jme/java?
Your advices are always helpful.
I try to use
[java]System.out.println(InetAddress.getLocalHost().getHostAddress()); [/java]
but it only got 192.168.0.100

1 Like

this might help
http://docs.oracle.com/javase/6/docs/api/java/net/NetworkInterface.html
do not know how to get ip with jme thou

by the way 192.168.0.100 is your ip, couse u are behind router
have u static ip? have you directed it to your pc?

Only your router knows for sure. There is no way to ask the local computer because it doesn’t know and wouldn’t easily know how to find out anyway.

the problem is solved after I use the code below:

whatismyip = new URL(“http://ifconfig.me/ip”);
BufferedReader in = new BufferedReader(new InputStreamReader(
whatismyip.openStream()));
String IP = in.readLine(); //you get the IP as a String
System.out.println(IP)

anyway, thank all who has helped me

1 Like

That’s going to give the ip address of your gateway though - still won’t let people talk to you unless they configure their gateway to forward the connection.

just enable dmz on your router and forward to pc (very unsafe) or just forward ports that u using for communication (quite safe)

Not ideal if you need all your players to do it though :wink:

<cite>@eraslt said:</cite> just enable dmz on your router and forward to pc (very unsafe) or just forward ports that u using for communication (quite safe)
<cite>@zarch said:</cite> Not ideal if you need all your players to do it though ;)

thanks for reply
the solved way I posted is not ideal, although it can return the ip address of user, it makes the program dead if the website is not running(temporary)
for this problem, I decide not to use any way to get ip address inside my game, because people are easy to get their ip address through the internet.
So just forget this post
I am getting a new problem for networking now, hope I can solve it by google