3

Although the Web implementation works, the android emulator as well as my device does not connect to WebSocket. The following event error code is received where the error is thrown and then disconnected:

    connection error 
Event {
  "isTrusted": false,
  "message": "Failed to connect to /127.0.0.1:8000",
}
connection closed
Event {
  "isTrusted": false,
  "message": "Failed to connect to /127.0.0.1:8000",
}
sib
  • 63
  • 5

2 Answers2

1

The default websocket port for android emulator is the following, which is different from web.

  android: "http://10.0.2.2:8000",
  web: "http://127.0.0.1:8000",
sib
  • 63
  • 5
0

@sib mentions the right ip but not the correct reason.

The reason why you need 10.0.2.2 on Android is that that's how you access the localhost via the android emulator. See the Android Docs.

On the iOs Emulator, you (should not) get the error, because there you access localhost on 127.0.0.1 as most people would anticipate

Laurenz Honauer
  • 254
  • 1
  • 12