dart-lang / web_socket_channel

StreamChannel wrappers for WebSockets.
https://pub.dev/packages/web_socket_channel
BSD 3-Clause "New" or "Revised" License
412 stars 107 forks source link

I tried to connect with localhost 8081 port but its connect with diffrent port #336

Open krButani opened 3 months ago

krButani commented 3 months ago

I tried to connect with localhost 8081 port but its connect with diffrent port Error show below

SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 127.0.0.1, port = 37702

code:

try {
      final wsUrl = Uri.parse('ws://127.0.0.1:8081/');
      final channel = WebSocketChannel.connect(wsUrl);

      await channel.ready;

      channel.stream.listen((message) {
        print(message);

        //channel.sink.close(status.goingAway);
      });
      channel.sink.add(
          '{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2lzaGFuYmhhaVwvaWJcL2RhXC8iLCJ0b2tlbiI6IiQyeSQxMCQ5QTAuU2xkWDlpQllzdXJ3QWc1MVwvT3ZyT0tcLzF2TDZkUFFFMER3aU5tSlNkdUFtM09ad1phIiwic2FtcGxlIjoiMiIsInRyaXAiOiI6OjEifQ.B-RqQ6gO-w1mWT3uVVAiObGKRaKKzH0LT5L4zDa_NoE"}');
    } catch (e) {
      print(e.toString());
    }
felixkarnodev commented 2 months ago

Any update to this issue?

anusha928 commented 1 month ago

This is because the localhost 8031 is not accessible by your mobile device. so u have to do adb reverse . the command is abd reverse tcp:8031 tcp:8031

if u are using emulator or simulator than use the server 10.0.2.2