How do I get a public IP address of a mobile phone? - java

I want to connect my phone to a server using the internet using the server's IP address. Mobile phone's IP address are normally private as far as I came to know.. To make my app work, I need a public Ip address of my phone. How do I achieve that??
Thanks

You'll have to wait for IPv6 ;) Now you get private address and the your service provider does some address translation (NAT): The router has one single public IP and uses ports to map incoming messages to IP addresses of the private network.
Your mobile's IP is invisible to the internet and the networks public IP is useless, because it is the router's address. Maybe with IPv6 we have public IPs for all mobiles, but for now you'll have to find a different solution for your problem - public IP doesn't work with mobiles as with all other clients in private networks (behind routers).

Setup your own hosting server, make your app "goto" that server, fetch a simple txt page, in that simple txt you dynamically on the server set the address that was used to get the txt.
Example:
Server: yourexample.com
url for /ip.php
ip.php just respondes with mimetype text and the address of the requesting client.
J2ME:
Request yourexample/ip.php in the repsonse is the address of your app.

astonishingly - t-mobile 3g service seems to assign a public IP. I'm still looking into the details, but I've seen an internet-available website running on a tethered laptop

You should get your i/p address. Open your browser and enter http://whatismyipaddress.com/ or wait till you have You'll have to wait for IPv6

Related

How to find specific desktop's ip address on network?

I'm coding an app which consist of two pieces. Desktop and android. There is one desktop and several android devices. (don't know the count.) I want to communicate android devices between desktop with TCP. However, android devices doesn't know desktop's lan ip address.
I thouht 2 ways:
1-Desktop app changes the local ip address on start. So android devices know the ip address. (I coded with that ip address)
2-Desktop app always tries to connect ip addresses (192.168.0.1 - 192.168.0.255) to sent desktop's ip address. And when an android device connect to the network accept the connection then know desktop's ip.
But there is some problems in both ways.
On first, you must be administrator to changing lan ip. So run command as admin with java is a problem. Because if I do this, when user start the program, uac always asks for it.
On second, I think there will be performance issues because of app always tries to connect. Exept this, when android device connect and dhcp gives it 192.168.0.5 , but loop is on 192.168.0.150. So android device have to wait for connection.
Is there a better way than these?
Look at this post Network discovery in Java using multicasting
I think this would be the best way to do it.
The server will listen for a broadcast message from client
the client sends a broadcast request asking for server ip
server receives request and replies back with server ip.
You can use the hostname. If the network is properly configured, the host name will point to the correct ip even if it changes

Socket communication on Android localhost

I'm developing multiple applications which need to communicate with each other via socket. First I need them to be able to communicate on localhost. So when I'm running both of them at the same time on my phone they can communicate (I know that there are easier ways to do this on the same phone but in the future they will run on separate phones).
My code for socket communication is very similar to this: link
Difference is that my apps are running this as foreground services.
I've set the ip for the server on the client to 127.0.0.1 but they just won't connect (not in the emulator and not on real phone). What am I missing?
UPDATE:
I've found an easy way to get the device own IP address, so instead of localhost I use this (with www.google.com domain): answer to "java InetAddress.getLocalHost(); returns 127.0.0.1 … how to get REAL IP?"
Maybe it's not too nice but it works.
You'll need to set the local IP address of each one, so they can communicate within your LAN. So use an address like 192.168.1.X. Both if you're running your devices as virtual or physical, you may easily know the local IP address they have accessing your router's web interface and seeing their bound IPs.

Locating IP on network

I have searched the web for this with no success.
This is my problem: I am developing an app that reads data from arduino connected with Ethernet shield.
I can connect to it on the internal network (home network) or through the Internet.
The problem is I need to know if the arduino is present on the local network and if not then look for it on the external ip address.
I have tried to use the ping function but it’s not working. Any help would be appreciated.
I presume you know the IP address of the arduino?, have you tried putting your pc\laptop onto the same subnet as the device, e.g. if the arduino has an IP address of 10.254.103.20 you could change the IP of your laptop\pc to 10.254.103.21 and then try pinging it?
Well for one thing, if your router supports NAT loopback (most do, but you may have to enable it) you can always just connect to the external IP address, regardless of whether you're on LAN or WAN.
Cheers,

Submit server IP from wifi router to Android

I'm currently writing an app that's to connect to a server over a wireless lan.
So far, I've got the IP address hardcoded into the app (which works perfectly), however, the next logical step is to be able to send the app the server IP address.
From what I understand, the router needs to broadcast the IP address over 255.255.255.255 - apart from that, I have no idea what to do.
Any and all help is greatly appreciated
edit
ok, so I know to get this working, all phones have to be on the same network as the server, which is fine.
What I need to do is get the phone to broadcast on the network whilst my server listens. From there, the server sends the app its IP address, then the rest of the code can continue.
Does anyone have a tutorial or anything I can follow to get both sides working?
one simple solution for you not to hardcode the server's IP or name (let us say it changes over time), would be for you to implement a name server on your network and have the android device call a local URL.
you could then post the current server's IP or name in the header of a web page on your local network. this response would then be used by android app.

Can't send P2P message from real IP

I need to send messages to Android phones through P2P on 3G connection.
Sending and receiving works perfectly on lan ip addresses(on wi-fi) but not on 3g or 2g.
On 3g I send a message but it never appears on the other end of the line.
Can anyone tell me how to make a connection ?
What port to use ?
Thanks,
DataSmith
DataSmith, what you refer to as internal and external IP address is most probably private IP address and public IP addresses. Private IP address are valid only on the lan where the device is located. This is why you can connect to other peers on the LAN.
However, there is no way you can connect alone to peers on other LANs (unless they have a public IP address on their LAN, which most probably is not the case). You need to learn about IP address translation and NAT traversal to achieve this. You can check the Practical JXTA II book available online for reading at Scribd.

Categories

Resources