Mikhail Kiselyov
Mikhail Kiselyov

Reputation: 55

Android run external Socket Server from any device

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:

  1. When I'm trying to setup server with external IP, I get java.net.BindException: bind failed: EADDRNOTAVAIL (Cannot assign requested address)
  2. 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).

Upvotes: 0

Views: 192

Answers (2)

blackapps
blackapps

Reputation: 9282

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. –

Upvotes: 1

user14644949
user14644949

Reputation: 321

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.

Upvotes: 1

Related Questions