-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
51 lines (33 loc) · 1.1 KB
/
test.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
/**
* Created by gabriel on 9/24/16.
*/
const Chat = require('./lib/chat');
require('colors');
var chat = Chat({port: 3355});
function logIncomingMessage(data, socket) {
var remoteAddressSays = "[" + socket.remoteAddress + "] says";
console.log(remoteAddressSays.bold);
console.log('\t' + data.toString());
}
function logConnection(socket) {
var remoteAddressConnected = "[" + socket.remoteAddress + "] connected";
console.log(remoteAddressConnected.bold.green);
}
function logClose(socket) {
var remoteAddressConnected = "[" + socket.remoteAddress + "] closed";
console.log(remoteAddressConnected.bold.red);
}
function logBusy(socket) {
var remoteAddressConnected = "[" + socket.remoteAddress + "] busy";
console.log(remoteAddressConnected.bold.blue);
}
function logOutcomingMessage(data) {
chat.write(data);
console.log('You say:'.bold);
console.log('\t' + data.toString());
}
chat.on('connect', logConnection);
chat.on('busy', logBusy);
chat.on('close', logClose);
chat.on('data', logIncomingMessage);
//////////////////////////////////////////////////////