-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_server.js
37 lines (28 loc) · 933 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
// *************************** create server ******************************
var port = 11000;
var server = require("./index").server;
var clientList = [];
var options = {
port:port
}
server.setDebuger(logger)
server.listen(options, onClientConnected, onClientDisconncted, onClientReceived);
function onClientConnected (socket) {
// clientList.push(socket);
}
function onClientDisconncted (socket) {
// var index = clientList.indexOf(socket);
// if (index != -1) {
// clientList.splice(index, 1);
// }
}
function onClientReceived (tag, value, from) {
// server.broadcast(tag, value) // all
server.broadcast(tag, value, null, from) // all, except from
// server.broadcast(tag, value, clientList, from);
}
function logger (log) {
var now = new Date()
var time = now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds()
console.log('[' + time + '] ' + log)
}