I'm extremely new to any kind of web-development so sorry in before-hand if what I write makes no sense. I'm working on a website that can get and post data through a website to a machine. (Client/Browser <-> Webserver <-> Machine). I'm having a problem though opening a websocket to be used by the Webserver <-> Machine connection. I use Javascript since I couldn't find any other viable solution to make this work. My code looks like this:
const WebSocket = require('ws');
const webSocketServer = new WebSocket.Server({port: 4000});
webSocketServer.on('request', function(request) {
console.log("test!");
const connection = request.accept(null, request.origin);
});
I use npm to start the web server and there are no errors, warnings or crashes. When I use postman however to send a GET request it gives the code "426: Upgrade Required" But I'm guessing that's simply because I don't do anything yet with the connection. My main problem is the the console is not logging the "test!" when I send out this request. What am I doing wrong? Is there a better solution to this that I'm not seeing?