forked from 1c3t3a/rust-socketio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket-io.js
47 lines (44 loc) · 1.45 KB
/
socket-io.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
const server = require('http').createServer();
const io = require('socket.io')(server);
console.log('Started');
var callback = client => {
console.log('Connected!');
client.on('test', data => {
// Send a message back to the server to confirm the message was received
client.emit('test-received', data);
console.log(['test', data]);
});
client.on('message', data => {
client.emit('message-received', data);
console.log(['message', data]);
});
client.on('test', function (arg, ack) {
console.log('Ack received')
if (ack) {
ack('woot');
}
});
client.on('binary', data => {
var bufView = new Uint8Array(data);
console.log(['binary', 'Yehaa binary payload!']);
for (elem in bufView) {
console.log(['binary', elem]);
}
client.emit('binary-received', data);
console.log(['binary', data]);
});
client.on('binary', function (arg, ack) {
console.log(['binary', 'Ack received, answer with binary'])
if (ack) {
ack(Buffer.from([1, 2, 3]));
}
});
client.emit('Hello from the message event!');
client.emit('test', 'Hello from the test event!');
client.emit(Buffer.from([4, 5, 6]));
client.emit('test', Buffer.from([1, 2, 3]));
};
io.on('connection', callback);
io.of('/admin').on('connection', callback);
// the socket.io client runs on port 4201
server.listen(4200);