我試圖去用這個鏈接http://web-engineering.info/node/57無法加載資源:服務器的狀態爲迴應426(需要升級)
的教程但是,當我執行節點server.js並打開瀏覽器http://localhost:3434它說需要升級。在server.js文件是:
var WebSocketServer = require('ws').Server,
wss = new WebSocketServer({port: 3434});
wss.broadcast = function (data) {
var i = 0, n = this.clients ? this.clients.length : 0, client = null;
for (; i < n; i++) {
client = this.clients[i];
if (client.readyState === client.OPEN) {
client.send(data);
}
else console.error('Error: the client state is ' + client.readyState);
}
};
wss.on('connection', function (ws) {
ws.on('message', function (message) {
wss.broadcast(message);
});
});