3
3
33remido2021-06-28 13:51:41
React
33remido, 2021-06-28 13:51:41

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));
    })
}


60d9a9b6e77e0066941610.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
3
33remido, 2021-06-28
@33remido

solved the problem by changing the port

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question