31 lines
739 B
JavaScript
31 lines
739 B
JavaScript
import Consumer from '../src/consumer'
|
|
|
|
const USOCKET = '/opt/sockets/samplecs.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'}
|
|
|
|
;
|
|
(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)
|
|
})
|
|
|
|
|
|
// This is your socket handler waiting on a message to do something
|
|
function app (packet) {
|
|
console.log('incoming packet from socket to process')
|
|
console.dir(packet)
|
|
}
|