-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathucat.js
executable file
·38 lines (34 loc) · 854 Bytes
/
ucat.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
#!/usr/bin/env node
const socket = require('./')({ allowHalfOpen: false })
var host = null
var port = 0
for (var i = 2; i < process.argv.length; i++) {
if (process.argv[i][0] !== '-') {
const parts = process.argv[i].split(':')
port = Number(parts.pop()) || 0
host = parts.pop()
}
}
if (process.argv.indexOf('-l') > -1) {
socket.listen(port)
socket.maxConnections = 1
socket.on('connection', onconnection)
} else {
if (!port) {
console.error('Usage: ucat [-l] host:port')
process.exit(1)
}
onconnection(socket.connect(port, host))
}
function onconnection (connection) {
process.stdin.pipe(connection).pipe(process.stdout)
connection.on('end', function () {
process.exit()
})
connection.on('close', function () {
process.exit()
})
process.once('SIGINT', function () {
connection.end()
})
}