Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Websocket connection from companion erroring with no reason

I've got a websocket server running on Replit using the node.js ws library (wss://FitPlace.codingmaster398.repl.co)

I've then tried to connect to it via the companion like so:

import * as messaging from "messaging";

let websocket = new WebSocket('wss://fitplace.codingmaster398.repl.co/');

websocket.addEventListener("open", onOpen);
websocket.addEventListener("close", onClose);
websocket.addEventListener("message", onMessage);
websocket.addEventListener("error", onError);

function onOpen(evt) {
   console.log("CONNECTED");
}

function onClose(evt) {
  console.log(`${evt.reason}`)
  console.log("DISCONNECTED");
}

function onMessage(evt) {
   console.log(`MESSAGE: ${evt.data}`);
}

function onError(evt) {
  console.log(evt.reason)
   console.error(`ERROR: ${evt.data}`);
}

messaging.peerSocket.addEventListener("open", (evt) => {
  console.log("Ready to send or receive messages");
});

The server shows no logs, even when it logs something upon every new connection.

The console shows "ERROR: undefined" paired with "DISCONNECTED"

Looking at the disconnect reason it gives "1006".

 

Any help?

Best Answer
0 Votes
1 REPLY 1

There could be many things wrong here. But it seems like you aren't trying to push data through so it's likely it just failed to connect to the websocket.

 

An 1006 error would have been returned on your function onError(evt). Which is general error handling. I'm not sure if there is a way to print out a more detailed error message here

 

From my limited experience with Websockets, it could be something is wrong with your web address itself, or the server itself is refusing the connection.

Best Answer