简体   繁体   English

SocketException:连接被拒绝(操作系统错误:连接被拒绝,errno = 111),地址 = localhost,端口 = 44382

[英]SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = localhost, port = 44382

在此处输入图像描述

This error is getting while using HTTP GET method使用 HTTP GET 方法时出现此错误

This happens because the localhost (or 127.0.0.1 ) on the device is only accessible to the device itself.发生这种情况是因为设备上的localhost (或127.0.0.1 )只能由设备本身访问。

Solution 1 (Android only)解决方案 1(仅限 Android)

You can reverse-proxy a localhost port to the Android device/emulator running adb reverse on the command prompt like so:您可以将localhost端口反向代理到在命令提示符下运行adb reverse的 Android 设备/模拟器,如下所示:

adb reverse tcp:5000 tcp:5000

Solution 2解决方案 2

Use the machine's IP address where the DB is running.使用运行 DB 的机器的 IP 地址。 Also, the DB should be listening to the IP 0.0.0.0 to be accessible outside the localhost .此外,数据库应该监听 IP 0.0.0.0以便在localhost之外访问。

Supposing the DB machine's IP is 192.168.1.123 it's going to be something like:假设数据库机器的 IP 是192.168.1.123它将是这样的:

Future db() async {
  print('@');
  final conn = await MySQLConnection.createConnection(
    host: '192.168.1.123',   // <- Here
    port: 3306,
    userName: 'root',
    password: '',
    databaseName: 'flutter', // optional
  );
  print('^');
}

Just take care because changing the DB to listen to 0.0.0.0 is a security risk as the DB is going to be accessible to the outside world.请注意,因为将数据库更改为侦听0.0.0.0会带来安全风险,因为外部世界将可以访问数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序无法在 android 上运行 [连接被拒绝(操作系统错误:连接被拒绝,errno = 111)] 地址 = 本地主机,端口 = 51034 - App in not working on android[ Connection refused (OS Error: Connection refused, errno = 111) ] address = localhost, port = 51034 未处理的异常:SocketException:操作系统错误:连接被拒绝,errno = 111,地址 = 127.0.0.1,端口 = 40712 - Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = 127.0.0.1, port = 40712 urlopen 错误 [errno 111] 连接被拒绝 - urlopen error [errno 111] connection refused Errno111 连接被拒绝 Kivy 套接字错误 - Errno111 Connection Refused Kivy Socket Error SocketException:连接被拒绝 - SocketException: Connection refused AndroidViewClient中的Culebra返回“ RuntimeError:错误:连接到 - Culebra in AndroidViewClient returns "RuntimeError: ERROR: Connecting to <socket… [Errno 111] Connection refused 使用 10.0.2.2 地址拒绝 Webview 本地主机连接 - Webview Localhost Connection refused using 10.0.2.2 address Android连接在本地主机上被拒绝 - Android Connection Refused on localhost 在Android中拒绝连接到本地主机 - Connection to localhost refused in Android 连接错误-连接被拒绝 - Connection error - connection refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM