H5 WebSocket 客户端
WebSocket测试
node.js WebSocket 服务端
// 引入WebSocket模块
const ws = require('nodejs-websocket');
const PORT = 10086;
ws.createServer((conn) => {
console.log('与客户端链接成功!');
conn.on('text', (msg) => {
console.log(msg)
conn.sendText('WebSocketClient 你好!');
})
conn.on('close', () => {
console.log('与客户端断开链接!');
})
conn.on('error', (err) => {
console.log(err);
})
}).listen(PORT);
const network = require('os').networkInterfaces();
const ip = network[Object.keys(network)[1]][0].address;
console.log(`ws://{ip}:{PORT}`);