How to bind a Socket to a Network interface

Viewed 362

The app must connect to a socket server hosted at 192.168.0.10:35000 by an IoT device through a WiFi network it provides while having an active data connection.

The following code throws an error:

SocketException: Connection timed out, host: 192.168.0.10, port: 35000

this._socket = await Socket.connect('192.168.0.10', 35000);

If I disable the mobile's Data connection, it connects as it should. I think that confirms that the Socket is not bound to the WiFi network.

On a native Android environment, I believe that the ConnectivityManager.bindProcessToNetwork() method, or the Network.getSocketFactory() method, would do the trick.

Is there any way to achieve this without writing native code?

Some extra information:

Running InternetAddress.lookup() on '192.168.0.10' gives the following:

image

Running NetworkInterfaces.list() gives the following:

image

0 Answers
Related