I'm new to using web sockets in nodejs in my electronjs project. My goal is to connect to the connection my server is running, I have everything setup correctly, the port, password, and localhost, all seemed to work using another package. But when I try to create this on my own, I can't seem to get this to work.
const WebSocket = require('ws');
serverip = 'localhost';
serverport = 25575;
serverpass = 'password';
const ws = new WebSocket('ws://' + serverip + ':' + serverport + '/' + serverpass + '/');
ws.on('open', function open() {
ws.send('/kick Player');
});
ws.on('message', function incoming(data) {
console.log(data);
});
ws.on('close', function close() {
console.log('disconnected');
});
What I have above is what I have so far, my console from the server I'm trying to connect to says that it is getting a connection from my pc, but doesn't relay any info besides that.
Server Output:
Rcon connection from: /127.0.0.1
This is an error I am getting in my electronjs console:
Uncaught Error: socket hang up
at createHangUpError (_http_client.js:334)
at Socket.socketOnEnd (_http_client.js:435)
at Socket.emit (events.js:199)
at endReadableNT (_stream_readable.js:1141)
at processTicksAndRejections (internal/process/task_queues.js:81)
Any help would be greatly appreciated.