Websocket 在线测试
Websocket 的调试总是很麻烦,需要服务端的支持,有时候你都不知道是哪里出了问题,故此工具可以测试某个服务端是否正常运行。
1. 参数设置
Node.js 服务端示例 ▼
const WebSocket = require('ws');
// 创建WebSocket服务器实例,监听端口3000
const wss = new WebSocket.Server({ port: 3000 });
wss.on('connection', function connection(ws) {
// 当客户端连接时触发
console.log('connection')
ws.on('message', function incoming(message) {
// 当服务器接收到客户端发来的消息时触发
console.log('received:', message.toString());
ws.send(message.toString())
});
// 发送消息到客户端
ws.send('something');
});
console.log('WebSocket server is running on ws://localhost:3000');
2. 消息记录
{{ logs }}