• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Push Registry: how to get the device IP

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic