-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (32 loc) · 870 Bytes
/
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
var socketio = require('socket.io');
const ArgumentParser = require('argparse').ArgumentParser;
color = require('ansi-color').set;
const parser = new ArgumentParser({
version: '0.0.1',
addHelp: true,
description: 'NetPickle Server'
});
parser.addArgument(
['-p', '--port'],
{
help: 'the port to launch the server',
required: true
}
);
let args = parser.parseArgs();
const io = socketio.listen(args.port);
const SHELL = color('NetPickle$ ', 'blue');
function log(message) {
console.log(SHELL + color(message, 'cyan'));
}
io.on('connection', function (socket) {
log('a user connected');
socket.on('disconnect', function () {
log('user disconnected');
})
});
io.sockets.on('connection', function (socket) {
socket.on('send', function (data) {
io.sockets.emit('message', data);
});
});