Issue
I am trying to connect flutter to my flask backend. But flutter gives following error
Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = 127.0.0.1, port = 50512
I even tried using my ipv4 address even localhost even host 0.0.0.0 and tried various ports but everytime the port keeps changing in flutter error. Sometimes like this
Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = 127.0.0.1, port = 39223
Can anyone suggest how do I solve this. Here is my flask code
port = int(os.environ.get('PORT', 5000))
if __name__ == '__main__':
app.run(debug=True, host='127.0.0.1', port=port) // changing to 0.0.0.0 also doesn't work neither different ports
I am able to connect to heroku server but not on localhost.
Solution
Try giving 'localhost' as host in app.run() and port 5000. It will work on your real device. If using emulator then can use "10.0.2.2". Let me know if it works for you.
Answered By - user13116294
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.