• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Push Registry: how to get the device IP

 
Ricardo Lecheta
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I would like to develop an J2ME application that you use Push Registry. I need start the application from a Socket Connection...

But to my server connect using socket in my device, I need to know the device IP adddress, how can I get it?

thank you
 
Eduardo Marques
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should be moved to the J2ME forum.

Anyway, to know the phone's IP use method getLocalAddress() in ServerSocketConnection
(or SocketConnection)



Also, according to the MIDP specs "The local hostname (if available) can be accessed from System.getProperty("microedition.hostname")"

Anyway, you may have a problem if the phone's IP changes over time. A possible solution to overcome this may be having your J2ME app register its IP regularly so that clients can contact you later, ie some kind of server registry mechanism.
[ March 21, 2007: Message edited by: Eduardo Marques ]
 
Ricardo Lecheta
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eduardo,

thanks for the answer..

>>ServerSocketConnection ssc = ...;
>>String ip = ssc.getLocalAddress();
I've already tried that.. but i could not "ping" this ip from my machine.

The System.getProperty("microedition.hostname") returns "localhost" for me :-)

I also tried to connect to a Servlet using the HttpConnection, that returns the Client address, using the request.getRemoteAddr() . But again I could not ping this Ip from my machine...

Am I doing something wrong?

thank you,
Ricardo
 
Eduardo Marques
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The fact that you're not getting any ping replies doesn't mean the IP does not exist.
The device may simply be ignoring ICMP request. Most phones won't reply to pings, as far as I know.

What you need to test is connecting to the TCP port you open, ie open a server port at the device then try to connect to it from the outside.

Also bear in mind that traffic to some ports may be filtered by the network.
[ March 23, 2007: Message edited by: Eduardo Marques ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic