quick-ws-server
v1.1.7
Published
Open websocket service quickly, which is suitable for nodejs and browsers.
Downloads
2
Readme
quick-ws-server
Support heartbeat and disconnection reconnection
examples
client
import WsServer from 'quick-ws-server'
const wsServer = new WsServer({
url: 'ws://localhost:4800'
})
wsServer.sendMsg(JSON.stringify({
time: Date.now(),
msg: 'hei'
})).then(res => {
// {
// msg: 'hello'
// }
console.log(res)
})
server
const WsServer = require('quick-ws-server')
const wsServer = new WsServer({
port: 4800
})
wsServer.onmessage = (ws, data) => {
// message:
// {
// time: Date.now(),
// msg: 'hei'
// }
console.log(JSON.parse(data))
// reply
ws.send(JSON.stringify({
msg: 'hello'
}))
}