我尝试发送有关 webSocket 标头的信息,并在连接时在服务器上读取它。像:
客户端代码很简单:
ws = await WebSocket.connect('ws://localhost.com:36485', headers: {
'codeName': 'Something',
},);
服务器代码:
var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({ port: 36485 });
wss.on('connection', function connection(ws) {
console.log(ws.upgradeReq.headers);
ws.on('message', function incoming(message) {
console.log('received: %s', message);
});
});
我的例外是:
类型错误:无法读取未定义的属性“标题”
幕布斯7119047
喵喔喔
相关分类