我尝试过'ws',我可以连接;几秒钟后;我收到封闭消息;
const WebSocket = require('ws');
var url = 'wss://wsocket.com:443/api/svc/v1/org/live';
const webSocket = new WebSocket(url, {
perMessageDeflate: false,
headers: {
Authorization: `Basic Yndpbm5ld2NvbTAwMDAwMTp0ZXN0MTIz`,
},
});
webSocket.on('open', function open() {
console.log('Connection has been established.');
});
webSocket.on('message', (message) => {
console.log('message received:'+ message);
});
webSocket.on('error', function(code, reason){
console.log('error occured: code'+ code +' reason: '+ reason );
});
webSocket.on('close', function(code, reason){
console.log('client closed: code'+ code +' reason: '+ reason );
});
是否有其他Websocket库提供干净的API或如何使用“ ws”实现此功能
请在投反对票之前,请给我一个理由;如果您不明白这个问题;
答案 0 :(得分:0)
Socket.io效果很好。进行检查...易于使用且设置流畅。