| 12345678910111213141516171819202122232425262728293031323334 |
- const fs = require('fs')
- const W3CWebSocket = require('websocket').w3cwebsocket;
- // 房间号/用户名
- const client = new W3CWebSocket('ws://127.0.0.1:49800/123/123', 'echo-protocol');
- client.onerror = function () {
- console.log('Connection Error');
- };
- client.onopen = function () {
- console.log('已连接');
- // function sendNumber() {
- // if (client.readyState === client.OPEN) {
- // var number = Math.round(Math.random() * 0xFFFFFF);
- // client.send(number.toString());
- // setTimeout(sendNumber, 1000);
- // }
- // }
- // sendNumber();
- };
- client.onclose = function () {
- console.log('echo-protocol Client Closed');
- };
- client.onmessage = function (event) {
- if (typeof event.data === 'object') {
- console.log('文件', event)
- } else {
- const obj = JSON.parse(event.data)
- console.log('数据', obj)
- }
- };
|