http icon indicating copy to clipboard operation
http copied to clipboard

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

Open krButani opened this issue 2 years ago • 2 comments

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());
    }

krButani avatar Mar 30 '24 06:03 krButani

Any update to this issue?

felixkarnodev avatar Apr 11 '24 19:04 felixkarnodev

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

anusha928 avatar May 14 '24 09:05 anusha928