uci-socket/examples/client.mjs

33 lines
800 B
JavaScript

import Consumer from '../src/consumer'
const USOCKET = __dirname + '/sample.sock'
const socket1 = new Consumer(USOCKET)
const socket2 = new Consumer(USOCKET)
let packet1 = {name: 'socket1', cmd:'doit', data:'data sent by socket1'}
let packet2 = {name: 'socket2', cmd:'doit', data:'data sent by socket2'}
// This is your socket handler waiting on a message to do something
let app = {
processIt: function processPacket (packet) {
console.log('incoming packet from socket to process')
console.dir(packet)
},
ucpp: 'processIt'
}
;
(async () => {
await socket1.connect()
await socket2.connect()
await socket1.listen(app)
await socket2.listen(app)
socket1.send(packet1)
socket2.send(packet2)
})().catch(err => {
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
})