Answer the question
In order to leave comments, you need to log in
Why Websocket connection failed?
server.js
const ws = require('ws');
const wss = new ws.Server({
port: 6000
}, () => {console.log('Websocket started on port 6000')});
wss.on('connection', function connection(ws) {
ws.on('mesage', function (message) {
message = JSON.parse(message);
switch (message.event) {
case 'message':
broadcastMessage();
break;
case 'connection':
broadcastMessage(message);
break;
}
})
})
function broadcastMessage(message) {
wss.clients.forEach(client => {
client.send(JSON.stringify(message));
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question