mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
Re-organize code
This commit is contained in:
1 parent
8901b385ad
commit
d51a75e5bc
7 files changed
+7
-5
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import { stdin, stdout, exit } from 'process'
|
||||
import { io } from 'socket.io-client'
|
||||
|
||||
stdin.setRawMode(true)
|
||||
stdin.resume()
|
||||
stdin.setEncoding('utf8')
|
||||
|
||||
const socket = io('ws://localhost:3000')
|
||||
|
||||
socket.on('open', function open() {
|
||||
console.log('Connected to the server.')
|
||||
})
|
||||
|
||||
socket.on('message', function incoming(data) {
|
||||
stdout.write(data)
|
||||
})
|
||||
|
||||
socket.on('close', function close() {
|
||||
console.log('Disconnected from the server.')
|
||||
exit()
|
||||
})
|
||||
|
||||
stdin.on('data', (key) => {
|
||||
if (key === '\u0003') {
|
||||
socket.close()
|
||||
exit()
|
||||
} else {
|
||||
socket.send(key)
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user