-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (22 loc) · 790 Bytes
/
index.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
import net from 'net'
var server = net.createServer();
server.on('connection', handleConnection);
server.listen(9000, function() {
console.log('Server listening on port %j', 9000);
});
function handleConnection(conn) {
var remoteAddress = conn.remoteAddress + ':' + conn.remotePort;
console.log('New picosystem connection from %s', remoteAddress);
conn.on('data', onConnData);
conn.once('close', onConnClose);
conn.on('error', onConnError);
function onConnData(d) {
console.log(d.toString());
}
function onConnClose() {
console.log('Connection from %s closed', remoteAddress);
}
function onConnError(err) {
console.log('Connection %s error: %s', remoteAddress, err.message);
}
}