2018-01-08 13:06:01 -08:00
|
|
|
import Consumer from '../src/consumer'
|
|
|
|
|
2018-01-10 15:03:32 -08:00
|
|
|
const USOCKET = __dirname + '/sample.sock'
|
2018-01-08 13:06:01 -08:00
|
|
|
|
|
|
|
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'}
|
|
|
|
|
2018-01-10 15:03:32 -08:00
|
|
|
// 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'
|
|
|
|
}
|
|
|
|
|
2018-01-08 13:06:01 -08:00
|
|
|
;
|
|
|
|
(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)
|
|
|
|
})
|