06-05-2019 00:29
06-05-2019 00:29
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.
06-13-2019 03:24
06-13-2019 03:24
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
06-06-2019 15:12
Are you getting this error in your /companion code?
Which mobile phone OS/version are you using?
06-07-2019 01:03
06-07-2019 01:03
Ipod, IOS
06-10-2019 08:30
06-10-2019 08:30
Which version of iOS?
06-10-2019 09:07
06-10-2019 09:07
Can you also post the code you're using too? Thanks
06-13-2019 01:14
06-13-2019 01:14
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
06-13-2019 03:24
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
06-13-2019 23:13
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
06-14-2019 00:59
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
05-17-2020 04:34
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://.