-
Notifications
You must be signed in to change notification settings - Fork 113
/
test-server.js
56 lines (44 loc) · 993 Bytes
/
test-server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var http = require('http')
var websocket = require('./')
var echo = require('./echo-server.js')
var WebSocketServer = require('ws').Server
var Buffer = require('safe-buffer').Buffer
echo.start(function(){
console.log('echo server is running')
})
function forBare (opts) {
var server = http.createServer()
websocket.createServer({
server: server,
binary: opts.binary
}, sendString)
server.listen(opts.port)
function sendString (stream) {
stream.write('hello world')
}
}
forBare({
port: 8344,
binary: false
})
forBare({
port: 8345
})
function checkIfDataIsBinary () {
var server = http.createServer()
var wss = new WebSocketServer({
server: server
})
server.listen(8346)
wss.on('connection', waitFor)
function waitFor (ws) {
ws.on('message', function (data) {
if (!Buffer.isBuffer(data)) {
ws.send(Buffer.from('fail'))
} else {
ws.send(Buffer.from('success'))
}
})
}
}
checkIfDataIsBinary()