How to terminate a WebSocket connection?

后端 未结 5 1639
执笔经年
执笔经年 2020-12-17 14:18

Is it possible to terminate a websocket connection from server without closing the entire server? If it is then, how can I achieve it?

Note: I\'m using NodeJS as bac

5条回答
  •  忘掉有多难
    2020-12-17 15:01

    According to the ws documentation, you need to call websocket.close() to terminate a connection.

    let server = new WebSocketServer(options);
    server.on('connection', ws => {
      ws.close(); //terminate this connection
    });
    

提交回复
热议问题