我正在尝试使用 websockets 在反应客户端和快速服务器之间建立连接。每次我尝试这个我都会得到一个错误。我想我错过了一些东西。
服务器代码:
var http = require('http');
var ws = require('ws');
var theHttpServer = http.createServer();
var theWebSocketServer = new ws.Server({
server: theHttpServer,
verifyClient: true
});
theHttpServer.on('request', app);
theHttpServer.listen(9000,
function () {
console.log("The Server is lisening on port 9000.")
});
theWebSocketServer.on('connection', function connection(msg) {
console.log("CONNECTION CREATED");
websocket.on('message', function incoming(message) {
});
});
客户端代码:
let wsConnection = new WebSocket("ws://localhost:9000");
wsConnection.onopen = function(eventInfo) {
console.log("Socket connection is open!");
}
错误:
if (!this.options.verifyClient(info)) return abortHandshake(socket, 401); ^
TypeError:this.options.verifyClient 不是函数