I am trying to develop an android application, through I could share some files or other applications in real time(can be thought as a miniature version of remote desktop sharing). So I am trying to set up a P2P connection between 2 phones, but for that phones would be requiring IP address of each other. Is there any way by which I can get the IP address of the other device by just using the phone number. If not then how will I get to know the IP addresses of the devices?
Could you please post some other suggestions for setting up a real-time P2P connection ?
The phones don't have public IP addresses, and aren't (usually) in the same subnet, so you can't just send IP packets directly from one to the other. You'll need a server to relay the packets. One way I've done this is to use the asmack library and an XMPP server like OpenFile.
Related
I created a UDP server on android app, and this UDP server is reachable via wifi (Local network). I can receive and send data. However when I change to 4G network. The UDP server on Android not able to receive anything. I use ip chicken to check my cell phone IP address and my UDP server port is 2004. Is there anything wrong? or my public ip is not correct?
Assuming that your phone IP address is correct, and it looks like you have checks this, it is important to know that mobile network providers may not support UDP inbound connections on their networks.
While it's not true to say that all don't, it is true to say that not all do so if you want your solution to be portable across networks you may need to look at alternatives anyway.
There are examples and guides on traversing network address translation boundaries on networks - one good example, which is looking at peer to peer applications, is here: http://bford.info/pub/net/p2pnat/
I have developed android p2p ip socket communication app.
It works well on local internet.
But I can't test it on network. For example my android device ip is 192.168.1.101, and others 10.45.33.21.(other country).
In this case can't connect devices each other.
I saw there isn't my ip address on Internet. and think my ip is changed on internet.
Really Is it impossible to connect on internet?
Thanks for reading.
192.168.x.x and 10.x.x.x are both private networks. This means that both devices are behind a NAT; it's impossible for one to connect directly to the other. You'll need a server on the Internet that the two can connect to and that will pass the data from one device to the other.
I"m building a P2P wifi app that requires bidirectional communication between every connected device and a central "host" (I've already addressed the issue of forcing the host onto that device in particular).
I've run through the developer.android tutorials and gotten all I can from those, but my issue at the moment is that I can't seem to get the host's sockets to connect to the P2P client devices properly...
My application for my host side currently displays all of the phones that have "connected" to it (via the p2p connect command) and has the addresses of all of those devices displayed in a list view on screen. These addresses are shown as IPV6(I think) addresses and are usually identical to the device's hard-coded MAC addresses, with one hex pair value changed. Example: Device's MAC is AA:BB:CC:DD:EE:FF and host's address for that device shows as being AA:BB:CC:DD:EE:13 (or similar).
The client side at this point in the workflow is waiting for the server to send it a small packet via port 8000.
However, at this point, when I attempt to connect from the host to any client, it throws the exception "Host could not be resolved..." and lists the device's IP address I'm trying to connect to, which properly matches the expected address that is displayed on screen of the connected devices.
I believe my particular concern revolves around the following line of code:
socket.connect((new InetSocketAddress(device.deviceAddress, 8000)), 5000);
Where device is the WifiP2pDevice that we are trying to connect to. In particular, looking at the InetSocketAddress help page, it expects our "device address" to be in the form of a string of IPV4 or IPV6. Is android's P2P "Device Address" really IPV6? Or am I missing something else completely obvious?
EDIT: I have been properly informed that P2P addresses are not applicable in any shape or form to sockets. The only way P2P sockets can be done this way in Android is:
1. Clients get the IP address of the group owner/server from the Broadcast receiver's P2PInfo object.
2. All of the clients connect to the server's ip using sockets.
3. As the server receives connections, the server can get the ip addresses from the client devices via the socket that is created for each client.
4. Once both parties have each others' IP addresses, proper bidirectional communication can be achieved.
I'm developing an Android application that needs to send local data to the Chromecast device. The Cast.CastApi.sendMessage() method works fine for small messages (up to about 100KB, it seems) but I need to pass images that may be several MB in size.
It seems that the best way is to bind to a local port on the Android device and listen for connections, pass a URL that points to the Android device in a message, and have the Chromecast fetch the images that way.
The problem is that I don't know what IP address to include in the URL. The Android device may have several IP addresses, not all of which are reachable from the Chromecast. There are two possible solutions I can think of but don't know how to implement either of them:
Extract on the Android the local IP address from the socket that is currently connected to the Chromecast. Use that as the host field in the URL.
Extract on the Chromecast the remote IP address from the socket that is currently connected to the Android. Send a dummy host from the Android and have the Chromecast substitute the correct address it has extracted.
Any suggestion on how to actually accomplish either of these? Or another option?
To make the media that is on your phone accessible to your receiver application running on chromecast, the easiest approach is to run a tiny web server in your app; you can use, for example, the NanoHttpd project. Note that Chromecast expects http(s) protocol for media transport unless it is included in the receiver itself. After adding that server, you can get the ip address of your Android device by accessing the WiFi network interface of your phone, see this post for example.
I have multiple T-Mobile Android cell phones and I am writing an app to go on all the phones that exchanges data via IP. Is there a way to get the private IP addresses of the cellular connections, and send data to each phone using those addresses?
You might wish to create some kind of intermediary web service that all of the devices talk to to share their IPs. Some kind of simple, RESTful API that I device could call to POST their IP/MEID and fetch the other devices' IPs.
You can use something like this to get your device IP.