mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
Change to use Socket.IO
This commit is contained in:
1 parent
c80a6fae6d
commit
f17c2a9ef5
4 files changed
+148
-20
No files matched your search
+6
-6
@@ -1,27 +1,27 @@
|
||||
import WebSocket from 'ws'
|
||||
import readline from 'readline'
|
||||
import { exit } from 'process'
|
||||
import { io } from 'socket.io-client'
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
})
|
||||
|
||||
const ws = new WebSocket('ws://localhost:8080')
|
||||
const socket = io('ws://localhost:8080')
|
||||
|
||||
ws.on('open', function open() {
|
||||
socket.on('open', function open() {
|
||||
console.log('Connected to the server.')
|
||||
})
|
||||
|
||||
ws.on('message', function incoming(data) {
|
||||
socket.on('message', function incoming(data) {
|
||||
console.log(`From server: ${data}`)
|
||||
})
|
||||
|
||||
ws.on('close', function close() {
|
||||
socket.on('close', function close() {
|
||||
console.log('Disconnected from the server.')
|
||||
exit()
|
||||
})
|
||||
|
||||
rl.on('line', (input) => {
|
||||
ws.send(input)
|
||||
socket.send(input)
|
||||
})
|
||||
Reference in new issue
Block a user