-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsocketio.js
executable file
·51 lines (43 loc) · 1.14 KB
/
socketio.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
var port = parseInt(process.argv[2]);
var io = require('socket.io').listen(3001);
var stdin = process.openStdin();
stdin.setEncoding('utf8');
stdin.on('data', function(chunk) {
process.stderr.write(chunk);
});
io.set('transports', [ process.argv[3] ]);
var main = io.sockets.on('connection', function(socket) {
socket.on('echo', function(data) {
if(data)
socket.emit('echo', data);
else
socket.emit('echo');
});
socket.on('echoSend', function(data) {
if (typeof data == 'object') {
socket.send(JSON.parse(JSON.stringify(data)));
} else {
socket.send(data);
}
});
socket.on('echoAck', function(data, ack) {
ack(data);
});
socket.on('requestAcknowledge', function(data) {
socket.emit('requestAcknowledge', data, function(data) {
process.stdout.write("__:ACKNOWLEDGE:" + data + "\n");
});
})
socket.on('message', function(m) {
process.stdout.write("__:MESSAGE:" + m + "\n");
});
});
var ns1 = io.of('/ns1').on('connection', function(socket) {
main.send("ns1");
ns2.send("ns1");
});
var ns2 = io.of('/ns2').on('connection', function(socket) {
main.send("ns2");
ns1.send("ns2");
});
process.stdout.write("__:OK\n");