[Python] Socket Exception, but on a different port?

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    Im trying to establish a websocket connection with an executable that starts it and the issue is flutter actually trying to connect to it. I want it to be connected to port 8765 and I've tried to make it clear and yet I get:

    SocketException (SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 192.168.1.104, port = 49832 )

    Why? it does this every time with a new 5 digit port?

    Future<void> localhostCheck() async {
    final port = 8765;
    print(port);
    final ip = await getLocalIP();
    print(ip);
    final uri = Uri.parse('ws://$ip:$port');

    if (_channel != null) {
    print("Closing existing WebSocket connection...");
    _channel!.sink.close(); // Removed status.goingAway
    _channel = null;
    }

    print("Trying to connect to WebSocket at $uri...");
    final channel = WebSocketChannel.connect(uri);
    await channel.ready;
    print("Connected to WebSocket at $uri");
    }


    and I get:

    I/flutter (25563): 192.168.1.104
    I/flutter (25563): Trying to connect to WebSocket at ws://192.168.1.104:8765...
    E/flutter (25563): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: WebSocketChannelException: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 192.168.1.104, port = 49832
    E/flutter (25563):

    Continue reading...

Compartilhe esta Página