• 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

ServerSocketConnection: what's the address that others can connect?

 
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone, I have to create a server in a midlet and connect to the server mobile phone with another client mobile phone, when I use:
(ServerSocketConnection)Connector.open("socket://"); // or specify a port number
getLocalAddress returns 127.0.0.1, which is just the localhost, so how do I create a server socket that has an inbound address(in a 3G network or GPRS network)?

I also tried push registry, however, it seems to be the same, I followed the instruction in:
http://developers.sun.com/mobility/midp/articles/pushreg/

the question is, what is the address that others can connect to you?

Thanks a lot!
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think of your mobile phone as a desktop computer, Other people's phones are also desktop computers in this visualization. When networking desktop computers together, you use a switch device.

In the case of mobile phones, the "switch device" is the phone company, and it's usually going to assign your mobile an IPv4 address using DHCP protocol. There's generally no way to predict what that address will be, and it will probably be different at different times.

What desktop computer usually do in a case like that is determine their IP address and push it out to a public DNS service like DynDNS.org so that others can locate you. However, since it's probably going to be a NAT address, you probably won't have a globally unique IPv4 address. Plus, there's a chance that the phone company won't route inbound connection requests to your phone.

As you found out, "localhost" resolves to 127.0.0.1. If you dig around a little, you can probably find your phone's hostname, and if you look up using that name instead of localhost, you'll probably get your actual assigned IP address.
 
reply
    Bookmark Topic Watch Topic
  • New Topic