Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = 127.0.0.1, port = 56782 python

I was trying to link the flutter app with python with API. My python code generated http://127.0.0.1:5000/ URL. When I used this in flutter code it threw the error

Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = 127.0.0.1, port = 56782

I found a solution in this video

Why does this solution work??

like image 699
sharmaji saheb Avatar asked Sep 12 '25 17:09

sharmaji saheb


1 Answers

If you use 127.0.0.1 in your emulator, it will refer to the android emulator not you pc.
And because there is no server running on android localhost at port 56782, it will create connection refused error.

In order to target you pc machine, where this emulator is running, you should be using 10.0.2.2. If you are using websocket and server is running on your pc, you can use ws://10.0.2.2 as socket url.

like image 88
Diwakar Avatar answered Sep 14 '25 07:09

Diwakar