Reputation: 57
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??
Upvotes: 4
Views: 3861
Reputation: 328
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.
Upvotes: 7