-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathteste.js
42 lines (29 loc) · 1.05 KB
/
teste.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
var net = require('net');
var string='';
var server = net.createServer(function(c) { //'connection' listener
//process.stdout.write('\033c');
var ip = c.remoteAddress + ":" + c.remotePort;
console.log(ip + ' -> connected');
c.write('hello\r\n');
c.on('data', function(data) {
var char = data.toString();
c.write('');
if (char.charCodeAt(0) == 13 || char.charCodeAt(0) == 10) {
console.log(ip+' -> '+string);
c.write(string+'\r\n');
if(string.toLowerCase()=='quit') {
c.end();
}
string = '';
} else
string += char;
console.log(char);
});
//c.pipe(c);
c.on('end', function() {
console.log(ip + ' -> disconnected');
});
});
server.listen(8001, function() { //'listening' listener
console.log('listening 8001');
});