Android Mobile-to-Mobile socket connection over public wifi? - android

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.

Related

Cannot create socket connection to Android device running hotspot

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.

Auto Connect to specific WiFi AP in presence of other remembered strong WiFi connections

I have a decive which reads data from serial and tranmits it over WiFi. (there is no global internet connection). It has an IP and port to which it can forward the read data over socket connection.
Now I have an android application which needs to connect to the device (lets call it D) using its ssid and presharedkey so that I can initiate socket connection and read data from device D.
This works fine if there is only one WiFi AP (i.e. device D) but in case mobile is connected to another WiFi then when I try to connect (via code similar to https://stackoverflow.com/a/8818490/504133) mobile connects to Device D WiFi for a moment and then gets connected to previously connected WiFi automatically.
How can I auto Connect to specific WiFi AP in presence of other remembered strong WiFi connections via code ?
(I have tried setting priority for WiFiConfiguration but it still does not work)

Use 3G for internet and WiFi for LAN in android

I am developing an android app to stream movies from local server on a WiFi. The WiFi does not have internet, it will be used only for accessing the streaming server.
What would make the app kickass is that the app users can continue using internet on their 3G while connected to my WiFi and streaming the movie.
I know for a fact that when android connects to a WIFI, the phone under the hood makes a call to clients.google.com/generate_204 to check if internet is available on the WIFI. If it receives no response, it continues using 3G along with being connected to the WiFi. However, in this scenario if my app makes a request to say 192.168.24.5 (ip address of my streaming server), it does not use WiFi to reach this ip but hunts for this address on 3G and fails.
What i need to achieve is that when android is connected to both my wifi and 3G, any call to private ip is directed to WiFi whereas any call to internet should use 3G.
Can this be done and how?

Socket communication with android devices

Can i interact with a server(android device) from a client(android device) just to query a database located in the server using TCP sockets?
And Yes and No.
If your device is within wireless network and have own local IP. You can connect to it from client phone if it is in the same network just providing proper IP and Port.
If server phone is located in another wireless network, then Port have to be forwarder using router settings to the server port. Bear in mind that if you will reconnect to wireless network by phone, then IP will be automatically assigned by network infrastructure and it might be changed from previous.
If you want to connect to server phone when it is on 3G network (or similar non wifi), you wont have any specific IP, and it is not static, that way it will be almost impossible to create reliable network. It is more Peer-to-Peer model of network you are looking for.
It is much better if you use Server in the middle as Gateway, that way it will be reliable. The only thing is that you will have to host server and its processes with all traffic and so on.

Using Socket to connect to Server in Pc from mobile

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.

Categories

Resources