Flutter - Socket.Connect() - SocketException: OS Error: Connection timed out

1,722

It was a strange problem, because there is no problem the code I shared. Windows Defender performed a rule to block to open a port as server. Hence, I started the server on my machine, however, I couldn't connect it from my Android device.

Maybe, the error code that is shown by Flutter isn't clear. If you took a error about socket programming for connection or binding, looking to Defender (or firewall) can be affective method. Unfortunately, as I was just starting to learn Flutter, I thought of checking out Defender afterwards.

Share:
1,722
Admin
Author by

Admin

Updated on December 27, 2022

Comments

  • Admin
    Admin over 1 year

    When I was working on debug mode (with "flutter run") by using my device (real), Socket.Connect() method doesn't work.

    Also I would like to say that this Connect method is in "dart:io" library.

    In shortly;

    • I opened a server (TCP) with Python.

    • I wrote the Flutter client like below to be able to connecting to the server in Python.

      Future den() async { print("Started"); Socket sock = await Socket.connect("192.168.0.159", 5431); print("Done +++++++++++++++++++++++++"); }

    However, I took a SocketError as Connection time out.

    The error message I took:

    E/flutter (17655): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: SocketException: OS Error: Connection timed out, errno = 110, address = 192.168.0.159, port = 43836
    

    NOTE: I tried to change the manifest file by adding INTERNET permission, but it is not working.