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:
Running NetworkInterfaces.list() gives the following:
Related
I am entering the ip of the machine I wanted to connect using vnc viewer but it's giving me this error:
So, that error means
No response was received from the specified IP address, even to reject
the connection.
Ways to fix this:
Check the remote computer is switched on. Ensure antivirus software lists VNC Server as an exception, and the firewall is configured to allow access on VNC Server’s listening port (5900 by default).
See if you are attempting to establish a direct connection over the Internet.
You can check any vnc error message from https://help.realvnc.com/hc/en-us/articles/360002254738-VNC-Connect-Error-Messages
I'm writing a Flutter application which involves getting some data from an HTTP server. Here's my code:
// the local IP of my testing server
final String SERVER = 'http://192.168.1.13:5000';
class Database {
Future<String> _getJob(int jobID) async {
var response = http.get('$SERVER?jobID=$jobID');
return response.body;
}
}
Currently this is the output:
[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception:
SocketException: OS Error: Connection refused, errno = 111, address =
192.168.1.13, port = 41966
Obviously this is happening because there isn't anything on port 41966, but the request shouldn't be going to that port, it should be going to port 5000. Is there a different way of specifying the port?
(my async code probably isn't very good, i'm going to work on it once i've figured this out)
Please specify which platform (Web, iOS, Android, Windows, Linux, mac, Flutter is amazing 😅) you're using. Its probably because Android/ iOS do not allow HTTP connections as they can be read by others on the same network. You need to use HTTPS.
I think for debugging, its better if you just called an API that already exists. Pick one from here: https://apilist.fun/ Then in the future, you can figure out how to get a TLS/SSL certificate assigned to your server (e.g. Using LetsEncrypt)
Alternatively you can go into the configuration of your application (platform specific config) to allow insecure connections (HTTP). For example, on Android and on iOS. However, Android and iOS default to this to make sure you consider security, not just send your data in plain text.
Note: its not actually because the server doesn't exist or the port is wrong. If the server didn't exist, it would say something like connection timed out or server unreachable. In your case, your OS/ platform immediately tells you OS Error: Connection refused, because it can see you're using HTTP.
I had the same issue.
Try using ngrok or a similar proxy. I think the dart HTTP client picks a random port when the host is not resolvable.
If you are pushing to an mobile device for testing your app, there is probably no reason a local IP address will be resolved.
I am new in android and trying to test my android app for socket connection between two emulators, one as server and second as client, as they can send and receive data. I created two projects for server socket and client socket with same package name in android studio 2.3.3 and want to run every project on separate emulator. I know to run this scenario I need to do port forwarding via telnet commands and know how to do it for default android studio emulators, but I want to use it for memu emulators. I don’t know if memu supports telnet, the way to do port forwarding is exactly the same like android studio emulators and if not (memu doesn’t support telnet) is there solution for my goal and how to do it?
I set ADB host port for first emulator (server socket) to 5559 , static ip 10.0.3.14 and for second emulator (client socket) to 5563, ip 10.0.3.15. When I run “telnet localhost 5558” to connect (memu) emulator console in cmd, result is this message: “Connecting To localhost...Could not open connection to the host, on port 5558: Connect failed”. But if I run “telnet localhost 5559” telnetlocalhost window appears! I really surprised because when run adb devices command it shoe 5558 port number (console port), but telnet work for 5559 port number (adb port).
I see in memu manager window, network settings,advanced there is a port forwarding button, but I don’t think it is the same I want. Also read on memu blog we can setup LAN with multiple MEmu instances via bridge connection, but I read another place “Network bridging does not work when the underlying physical network device is a wireless device”. So I confused if bridge connection can help me while I’m using laptop that (android)memu emulators run on it.
I really appreciated everyone can help me to find how connect two memu emulators for socket connection?
P.S: Finally, I apologize if I wrote more than enough and sorry for my poor English.
I am working with an app that uses ports 8000 and 9987 over wifi to talk to android devices. It works great
on everything but my Google TV.
Here is part of what I get in my Java Console when I try to use it
...
Connecting to: http://192.168.2.9:8000/_version?version=71
It did not work.java.net.ConnectException: Connection refused: connect
java.net.ConnectException: Connection refused: connect
...
That is the correct IP for the gtv.
Can it be done?
It is not clear from your description if the server component is running on the GTV device or the client. Also, you cannot assume that any particular port number would always be available to your apps. They could be used by other apps. You need to design assuming that you might not be able to bind to a particular port number. You could try a sequence of port numbers starting from your default port number, but make sure you have some way of uniquely identifying your process bound to a port. Or you could design a network broadcast discovery protocol that would tell your clients at which port the app is bound.
We have used port numbers like 8080 on GTV devices, so it is possible to use port numbers like that.
I am developing a network app for Android and I'm still stuck on connecting my real Android device with an device-emulator running on my desktop computer.
I've created private network with a router, so the only ones connected to the network are my pc and my mobile phone, in order to avoid firewall/closed ports problems.
My PC ip is 192.168.1.100 and I'm trying to ping each other so I can sea reachability of each network node. Ping works fine from my PC (not the emulator console) to the phone.
The problem is that I want to ping the PC-emulator from my mobile phone, not the PC itself... For that, I use the emulator console... Should I use my computer IP or should I use another one? I've seen some ip's like "10.0.x.x" here http://developer.android.com/guide/developing/tools/emulator.html
But I guess those are for connecting two EMULATORS, right?
Besides, I've tried to connect them by socket, creating a redirection for the port via Emulator console, but still can't connect them.
Any clues?
Thanks!!
I tried the early solution I gave you and it didn't work. As you said maybe the reason is the redir command of the emulator console only redirects packets comming from the localhost.
So I searched for a simple proxy server and used it in the same machine to test it out.
http://www.java2s.com/Code/Java/Network-Protocol/Asimpleproxyserver.htm
With this I used the following configuration:
on the proxy:
String host = "localhost";
int remoteport = 3000;
int localport = 4000;
Then run the emulator instance:
Server socket listening on port 2000.
Open telnet instance and issue "redir add tcp:3000:2000"
And finally on the real device open a socket to the machine address on port 4000.
So the network map looks like:
Device <-> machine:4000 Proxy machine:3000 <-> :3000 Emulator :2000 -> Application
This worked for me using the same application on the device and emulator.
I've reached the conclusion that emulator can only receives packets coming from the loopback (127.0.0.1), since when you issue "redir add tcp:port:newPort, it only redirects the first port (associated to the loopback) to the second port (associated to the "emulator virtual ip").
I've tried to create a bridge, which redirects all the packets coming to my pc to the IP 127.0.0.1, but still not works. Thus, I think the emulator has been developed only to communicate with other emulators...
I hope anyone that comes here contradicts me.
You may be able to connect a real device with an emulator instance.
Did you tried setting a redirection on the emulated device and then connect the real device trough a java socket?
For example:
On the emulated device open a server socket listening on port 2000, then open a telnet connection and issue the command:
redir add tcp:4000:2000
Finally, open a socket on the real device to your machine address (192.168.1.100) on port 4000.