mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
14 lines
309 B
JavaScript
14 lines
309 B
JavaScript
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!')
|
|
})
|