安装:
npm install ws
服务端(nodejs):
客户端:
var ws = new WebSocket("ws://localhost:8080");
ws.onopen = function (e) {
console.log('Connection to server opened');
sendMessage();
}
function sendMessage() {
ws.send('hello');
}
原文链接:https://www.f2er.com/nodejs/32866.html