06-05-2019 00:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-05-2019 00:29
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I am new to this and unable to understand why this happening - how do I resolve this? Please help
Answered! Go to the Best Answer.

Accepted Solutions
06-13-2019 03:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


06-13-2019 03:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I just tested this on Android 9.
// companion/index.js
const wsUri = "wss://echo.websocket.org/"; let websocket; function testWebSocket() { websocket = new WebSocket(wsUri); websocket.addEventListener("open", onOpen); websocket.addEventListener("close", onClose); websocket.addEventListener("message", onMessage); websocket.addEventListener("error", onError); } function onOpen(evt) { console.log("CONNECTED"); doSend("WebSocket rocks"); } function onClose(evt) { console.log("DISCONNECTED"); } function onMessage(evt) { console.log(`MESSAGE: ${evt.data}`); websocket.close(); } function onError(evt) { console.error(`ERROR: ${evt.data}`); } function doSend(message) { console.log(`SEND: ${message}`); websocket.send(message); } testWebSocket();
Which produces:
[11:22:40 AM] Companion: Companion launched by [launchedOnTracker] [11:22:41 AM] Companion: CONNECTED (companion/index.js:9,3) [11:22:41 AM] Companion: SEND: WebSocket rocks (companion/index.js:23,3) [11:22:41 AM] Companion: MESSAGE: WebSocket rocks (companion/index.js:14,3) [11:22:41 AM] Companion: DISCONNECTED (companion/index.js:14,3) [11:22:42 AM] Companion: Companion unloaded

06-06-2019 15:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


06-06-2019 15:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Are you getting this error in your /companion code?
Which mobile phone OS/version are you using?

06-07-2019 01:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-07-2019 01:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Ipod, IOS

06-10-2019 08:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


06-10-2019 08:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Which version of iOS?

06-10-2019 09:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


06-10-2019 09:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Can you also post the code you're using too? Thanks

06-13-2019 01:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-13-2019 01:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I am using below code in my companion app js and ios ver 10.3.3, android 9
const socket = new WebSocket('ws://localhost:8080');
socket.addEventListener('open', function (event) {
socket.send('Hi localserver!');
});
socket.addEventListener('message', function (event) {
console.log('Message from server ', event.data);
});

06-13-2019 03:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


06-13-2019 03:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I just tested this on Android 9.
// companion/index.js
const wsUri = "wss://echo.websocket.org/"; let websocket; function testWebSocket() { websocket = new WebSocket(wsUri); websocket.addEventListener("open", onOpen); websocket.addEventListener("close", onClose); websocket.addEventListener("message", onMessage); websocket.addEventListener("error", onError); } function onOpen(evt) { console.log("CONNECTED"); doSend("WebSocket rocks"); } function onClose(evt) { console.log("DISCONNECTED"); } function onMessage(evt) { console.log(`MESSAGE: ${evt.data}`); websocket.close(); } function onError(evt) { console.error(`ERROR: ${evt.data}`); } function doSend(message) { console.log(`SEND: ${message}`); websocket.send(message); } testWebSocket();
Which produces:
[11:22:40 AM] Companion: Companion launched by [launchedOnTracker] [11:22:41 AM] Companion: CONNECTED (companion/index.js:9,3) [11:22:41 AM] Companion: SEND: WebSocket rocks (companion/index.js:23,3) [11:22:41 AM] Companion: MESSAGE: WebSocket rocks (companion/index.js:14,3) [11:22:41 AM] Companion: DISCONNECTED (companion/index.js:14,3) [11:22:42 AM] Companion: Companion unloaded

06-13-2019 23:13
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-13-2019 23:13
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks, works fine, but when I use my URL "ws://127.0.0.1:9000/" then i am getting this error "WebSocket connection to 'ws://127.0.0.1:9000/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED"

06-14-2019 00:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


06-14-2019 00:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Connection refused sounds like your service isn't running on that port. Or, are you running that service on a server? If so, you'll need to change 127.0.0.1 to the IP address of the server.

05-17-2020 04:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-17-2020 04:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Just based on the comments, I read that only secure connections are support by device.
Therefore, wss:// protocol has to be declaired and not ws://.

