aspose file tools*
The moose likes Product and Other Certifications and the fly likes Push Registry: how to get the device IP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "Push Registry: how to get the device IP" Watch "Push Registry: how to get the device IP" New topic
Author

Push Registry: how to get the device IP

Ricardo Lecheta
Greenhorn

Joined: Dec 23, 2003
Posts: 7
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

Joined: Feb 19, 2005
Posts: 231
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 ]

Eduardo Marques
Get ready for your SCMAD certification at J2MECertificate.com - See what all the buzz is about ...
Ricardo Lecheta
Greenhorn

Joined: Dec 23, 2003
Posts: 7
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

Joined: Feb 19, 2005
Posts: 231
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Push Registry: how to get the device IP
 
Similar Threads
Port in URL string: is it for destination or for source?
Push Registry
Push Registry with socket or datagram connections
midlet suite question
web application with multithreaded sockets