I want to run a socket server on android, and read/write data from/to other android devices with different networks.
Here is the problem:
When I'm trying to setup server with external IP, I get java.net.BindException: bind failed: EADDRNOTAVAIL (Cannot assign requested address)
When I setup server with IPv4 address - other android devices from different networks can't connect to it.
What should I do, to link two or more android devices with sockets from different networks?
The main point is run server on any of that devices (client-server code in one app).
You can't bind to an address you don't have.
You need (a) to bind to an interface on your android device, and (b) arrange port forwarding / open the firewall (depends on router+network config) from your router to your android device.
You do not have to bind your server socket to an ip address.
Just dont call bind().
Further your server is only reachable if it runs on an Android device connected with wifi to a router.
If the Android device is on mobile connection your server is not reachable. –
Related
I have an ESP8266 that connects to my WiFi network after being configured (via WiFi Manager library) and runs a HTTP web server that displays certain sensor data. It connects to my specific network with a 192.168.0.XX IP and it works well.
My problem comes with the android app, and how to actually programmatically retrieve the IP that the webserver is running on? My routers DHCP only reserves IP's for a week - so hardcoding the IP into the app is not a good option, and having less tech-savvy people find the IP and configure it themselves is also not what I'm looking to do.
I also can't hardcode a static IP as friends & family will be using this with different networks and routers (so 192.168.0.X would not work on a router with an IP of 10.0.0.1 for example).
So, how do I go about programmatically getting the IP of my ESP8266 that is connected to my local network?
There is a solution that maybe isn't very optimal and professional, but will do for hobby project. You can make your android app scan your local network using http GET on all addresses - e.g. trying to GET something like this: http://192.168.0.X/sensor_status. You can configure your esp8266 device to respond with code 200 (OK) and save this address in your android app's persistent storage. Next time you can simply check if there is ip saved in persistent storage and try to connect to it. If esp8266 is not available under remembered ip, you can re-scan your network.
I developed a chat application which is working great on same wifi connections on different machines.
Concept is.. One Server program is running on One machine which is set by ip and particular Port number so that client hit to server on a particular Port number.
There are two wifi connection running FCS and FCS1
My laptop is getting access to FCS wifi and if client interface is running on same wifi it's working; but when it connects to FCS1 the server doesn't get the IP info from the FCS1 network.
I'm not sure whether the problem is redirecting the IP on the router. Do I need to configure the router?
If the server and the client are running on two different networks without a valid IP address for the server, you need to use a VPN connection.
Or if you have control over the router, you could give a static IP address to the server and redirect any traffic on port -say- 7644 on router to server:7644.
I'm trying to connect my pc to my android phone via WIFI..
But the problem is anytime I disconnect my phone from WIFI and turn it on again
I'm getting a different IP address so my pc doesn't connect until I change the IP address to connect to.. Is there any way to get the correct IP address of the phone?
That might be a router settings issue. Have you ever heard of "DHCP Reservation"? Most routers support such an option, which enables the router to memorize an IP to every distinct client ever connected and then to assign this ip to the respective client every time it reconnects.
Check your router settings / documentation for this option.
Here is a link, which could help you with your further investigation:
http://lifehacker.com/5822605/how-to-set-up-dhcp-reservations-so-you-never-have-to-check-an-ip-address-again
I am trying to set up a client/server model with android clients and a Java server.
The connection is over TCP.
I have all of my code working when the android device is on WIFI, however whenever I connect to a wireless network (eg 3g, 4g) the sockets refuse to connect.
I've been reading about NAT traversal but i'm not sure where to begin when implementing the necessary steps to allow the connection.
NOTE: my server has a static IP address
My guess is you have a network related problem. Assuming your server is behind a router, your server socket has to bind into its LAN IP (not directly binding the public internet IP). Then you need to setup port forwarding, firewall rules etc to ensure everyone on the internet can see your server (checking with online port open checker / telnet from another network is a good test)
I have created a TCP socket client in android and use a open src socket app which i use as a server to send messages to my android app, every thing works fine.
But the doubt is that both device are present using my home wifi connection hence having 192.x.x.x series ip,
But in case my device is connected to wifi router in my home having Ip of 192.x.x.x and server is having static Ip, will my server be able to send message to the remote device, irrespective of the fact there the device is having local network Ip ?
No, you won't be able to send data to the remote device unless and untill it initiates the connection , you cannot initiate a connection to a dynamic Ip(remote Device
)