-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (26 loc) · 815 Bytes
/
app.js
File metadata and controls
35 lines (26 loc) · 815 Bytes
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
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
})
const Net = require('net')
const port = 12000
const server = new Net.Server()
server.listen(port, function () {
console.log(`Server listening for connection requests on socket localhost:${port}`)
})
server.on('connection', function (socket) {
console.log('CONNECTED')
socket.on('data', function (chunk) {
console.log(`${chunk.toString()}`)
})
socket.on('end', function () {
console.log('CONNECTION CLOSED')
})
socket.on('error', function (err) {
//console.log(`Error: ${err}`)
})
readline.on('line', function (input) {
if(input.toUpperCase() == "Q") process.exit(0)
else socket.write(input.toUpperCase())
})
})