ws-simple
v1.0.0
Published
Web Socket
Downloads
1
Readme
install
npm i ws-simple
start
// server.js
const Server = require('ws-simple')
const server = new Server({ port: 3000 })
server.on('connection', socket => {
// Receive message from client
socket.on('message', message => {
message // output: 'foo'
// Send message to client
socket.send('bar')
})
})
// client.js
const socket = new WebSocket('ws://127.0.0.1:3000')
socket.addEventListener('open', () => {
console.log('connected')
})
// Receive message from server
socket.addEventListener('message', e => {
console.log(e.data)
})
// Send message to server
sendMsgBtn.addEventListener('click', () => {
socket.send('foo')
})