mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
Create a websocket server and client
This commit is contained in:
1 parent
0ca4bf0bc8
commit
c80a6fae6d
2 files changed
+40
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import { WebSocketServer } from 'ws'
|
||||
|
||||
const wss = new WebSocketServer({ port: 8080 })
|
||||
|
||||
wss.on('connection', function connection(ws) {
|
||||
console.log('Connected to the client.')
|
||||
|
||||
ws.on('message', function incoming(message) {
|
||||
console.log(`From client: ${message}`)
|
||||
})
|
||||
|
||||
ws.send('Hello from server!')
|
||||
})
|
||||
Reference in new issue
Block a user