diff --git a/test/index.js b/test/index.js index 6a89cfc..ea804fe 100644 --- a/test/index.js +++ b/test/index.js @@ -1,5 +1,2 @@ -const weServer = require('./websocketServer') - -weServer.on('connection',()=>{ - console.error('websocket-server connected'); -}) \ No newline at end of file +const wsServer = require('./websocketServer') +const wsClient = require('./websocketClient') diff --git a/test/websocketClient.js b/test/websocketClient.js new file mode 100644 index 0000000..fa13793 --- /dev/null +++ b/test/websocketClient.js @@ -0,0 +1,25 @@ + +const ws = require('ws') + +const wsClient = new ws.WebSocket('http://localhost:8000') + +wsClient.on('error', console.error); + +wsClient.on('open', function open() { + console.error('open'); + const array = new Float32Array(5); + + for (var i = 0; i < array.length; ++i) { + array[i] = i / 2; + } + + wsClient.send('yuyu',()=>{ + console.error('ζˆ‘ε‘ι€δΊ†'); + }); +}); + +wsClient.on('message',(message)=>{ + console.error('received: %s', message); + console.error(message,'message'); +}) +module.exports = wsClient \ No newline at end of file diff --git a/test/websocketServer.js b/test/websocketServer.js index b78e5cf..1b37e87 100644 --- a/test/websocketServer.js +++ b/test/websocketServer.js @@ -1,7 +1,18 @@ const ws = require('ws') -const weServer = new ws.WebSocketServer({port:8000}) +const wsServer = new ws.WebSocketServer({port:8000}) +wsServer.on('connection',(ws)=>{ + ws.on('error', console.error); + + ws.on('message', function message(data) { + console.error('received: %s', data); + }); + + ws.send('something'); +}) + +module.exports = wsServer + -module.exports = weServer