I have an Android phone running a hotspot and an app with a server socket running on port 10000.
The phones IP address is 192.168.43.1.
Another phone connects to the hotspot (address is 192.168.43.6) and tries to establish a socket to the other phone running the hotspot.
But that socket creation fails with a connection timeout.
Ping works in both directions and it works when both phone are connected to a regular WiFi router.
Is there some extra work required to get this scenario working on Android?
It looks like this is not possible: https://stackoverflow.com/a/17928091/2445758
You cannot open a connection to the phone acting as a hotspot from a client.
Related
I am working on an Android app that is able to control GPIO pins etc of a RaspberryPi. At the moment, I have to enter the IP-Address manually.
Is there some way to add a discovery-function, which finds the RaspberryPi in a network?
I want something which works out of the box when connecting the phone to wifi and connecting the RPi to the same network.
As far as I know all RaspberryPi devices start with the same MAC-Address prefix.
Just try to connect to several ip addresses which your raspi could have. Use port 10000. If your android device ip for instance is 192.168.1.6 then try all ip's from 192.168.1.3 to for instance 192.168.1.25. Don't try the 6. Set a socket connect time out of one second about otherwise you have to wait and wait before a connection times out.
I had this chat program using sockets and ip addresses.
I tried the code and was working perfectly on my android devices connected via wifi to my router.
I've got the client and server codes from here http://examples.javacodegeeks.com/android/core/socket-core/android-socket-example/
The code gets the ip address assigned by the router to the android device. The problem is how will I be able to communicate an android device connected to the Router A via wifi to an android device connected to Router B?
I want to have my app able to connect to other devices over the same wifi network and transfer some data, that is phone A and phone B have my app installed and are on the same network. I am able to connect two devices currently with one acting as server and the other being client but this is with a static IP reference to the server device. In the open world this IP will change of course so my problem is how do I get phone A to start up as a server device then have phone B see the server device on the network and connect to it. So the server device would accept this client connection and carry out the needed actions when the connection is made. Is this even possible?
I believe you would have A device listening on port number x, and the client version (device B) looking for that same port number x. This could be wrong.
This is a job for DNS. If you don't have a DNS server available you could invent a discovery protocol in which machine A periodically multicasts the IP & port on which it is listening.
Machine B joins the multicast group. Once machine B knows A's address and port it can open a socket using the code you already have.
I wrote an app to connect to java server running in PC. It works fine in emulator but its not working when i try the same from my mobile. I used the Mobiles 3G network to connect to IP address.
(Based on question comment)
I assume that your server application is running on the same machine as the android emulator. In this case the emulator can reach your server with 10.0.2.2.
If you're trying to contact your server via mobile 3G you have to use the IP of your Internet connection (What is my IP?). The request will reach your router. The router has to forward this request to your server machine. So if your server has a local IP 192.168.0.10 and it listens to port 2412 your router should forward all incoming request for this TCP port to this IP.
You should allow the 3G internet in Settings. (Emulator doesn't need this, it uses ethernet connection of your PC).
Your application should diagnose the state and possibilities of Internet connection and report it to you as a user of the debug mode. Or/and something - to the usual user.
I've written an Android app that includes creating a socket connection between 2 mobiles over wifi. The connection works fine at home with my wireless router and WEP security. However, when I tried to run the app at my local coffee shop, I could not make the socket connection. Both droids were connected to the shop's wireless network and the client was using the correct IP address. However, when I tried to make the connection, I received a SocketTimeoutException. I've tried this app at other (home-type with WEP) locations and as long as both mobiles are connected to the wifi network they can set up the socket connection.
Is there something in the configuration of public wifi networks that doesn't allow socket connections to be set up?
It can be that router in this coffe shop allows only specific ports like 80 for http and other ports are blocked by device, maybe you can try setting up your server on the device on such normally open port.