2018-01-27 23:20:33 -08:00
|
|
|
import Base from '../src/base'
|
|
|
|
|
2018-02-13 14:19:18 -08:00
|
|
|
// const USOCKET = __dirname + '/sample.sock'
|
2018-01-30 21:12:38 -08:00
|
|
|
|
2018-02-04 14:18:21 -08:00
|
|
|
const socketfuncs = {
|
2018-02-05 22:05:38 -08:00
|
|
|
write: {
|
|
|
|
happy: function(packet){
|
|
|
|
return new Promise( async (resolve) => {
|
|
|
|
let res = {}
|
2018-02-13 14:19:18 -08:00
|
|
|
res.response=packet.data+ ' and Im a happy puppy :)'
|
2018-02-05 22:05:38 -08:00
|
|
|
return resolve(res)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
sad: function(packet){
|
|
|
|
return new Promise( async (resolve) => {
|
|
|
|
let res = {}
|
|
|
|
res.response='Im a sad dog :('
|
|
|
|
return resolve(res)
|
|
|
|
})
|
|
|
|
}
|
2018-01-30 21:12:38 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 23:20:33 -08:00
|
|
|
|
|
|
|
|
2018-02-06 18:30:00 -08:00
|
|
|
const tcpfuncs = {
|
|
|
|
write: {
|
|
|
|
happy: function(packet){
|
|
|
|
return new Promise( async (resolve) => {
|
|
|
|
let res = {}
|
|
|
|
res.cmd='reply'
|
2018-02-13 14:19:18 -08:00
|
|
|
res.response=packet.data+ ' and Im a TCP happy puppy :)'
|
2018-02-06 18:30:00 -08:00
|
|
|
return resolve(res)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
sad: function(packet){
|
|
|
|
return new Promise( async (resolve) => {
|
|
|
|
let res = {}
|
|
|
|
res.cmd='reply'
|
|
|
|
res.response='Im a TCP sad dog :('
|
|
|
|
return resolve(res)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 23:20:33 -08:00
|
|
|
|
2018-02-13 14:19:18 -08:00
|
|
|
// const delay = time => new Promise(res=>setTimeout(()=>res(),time))
|
2018-01-30 21:12:38 -08:00
|
|
|
|
2018-02-06 18:30:00 -08:00
|
|
|
;
|
|
|
|
(async () => {
|
2018-01-29 21:51:13 -08:00
|
|
|
|
2018-02-13 14:19:18 -08:00
|
|
|
let fio = new Base({sockets:'uc#c>n,us#s>n,tc#c>t,ts#s>t,tc2#c>t', id:'four-in-one'})
|
2018-02-06 18:30:00 -08:00
|
|
|
// let fio = new Base({sockets:'uc#c>n,us#s>n', id:'four-in-one'})
|
|
|
|
await fio.init()
|
|
|
|
fio.s = socketfuncs
|
|
|
|
fio.st = tcpfuncs
|
|
|
|
fio.ct = {reply: packet =>{
|
|
|
|
console.log('==============Packet Displayed for TCP consumer received packets only')
|
2018-02-13 14:19:18 -08:00
|
|
|
console.dir(packet.response)
|
|
|
|
console.log('===========================')
|
2018-02-06 18:30:00 -08:00
|
|
|
}}
|
|
|
|
fio.cn = {
|
|
|
|
reply: function (packet) {
|
|
|
|
console.log('==============Replay for only Named Pipe Consumer=========')
|
2018-02-13 14:19:18 -08:00
|
|
|
console.dir(packet.response)
|
2018-02-06 18:30:00 -08:00
|
|
|
console.log('===========================')
|
|
|
|
}
|
|
|
|
}
|
2018-02-04 14:18:21 -08:00
|
|
|
|
2018-02-06 18:30:00 -08:00
|
|
|
fio.good = {
|
|
|
|
bad: function(packet){
|
|
|
|
return new Promise( async (resolve) => {
|
|
|
|
let res = {}
|
|
|
|
res.req = packet
|
|
|
|
res.cmd='good/ugly'
|
|
|
|
res.response='The Good The Bad and The Ugly'
|
|
|
|
return resolve(res)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
ugly: function (packet) {
|
|
|
|
console.log('==============reply from Good Bad command =========')
|
|
|
|
console.log(packet.response)
|
|
|
|
console.log('===========================')
|
|
|
|
}
|
|
|
|
}
|
2018-01-29 21:51:13 -08:00
|
|
|
|
|
|
|
let packet = {}
|
2018-01-30 21:12:38 -08:00
|
|
|
console.log('=============sending============')
|
2018-02-06 18:30:00 -08:00
|
|
|
// packet = {cmd:'echo', data:'some data to echo'}
|
|
|
|
// console.log(packet)
|
2018-02-13 14:19:18 -08:00
|
|
|
// await fio.send(packet,'uc')
|
|
|
|
packet = {cmd:'write:happy', data:'My name is Zoe'}
|
|
|
|
console.log(packet)
|
|
|
|
//console.log(await fio.send(packet))
|
|
|
|
console.log(fio.getPacketByName('uc',await fio.send(packet)).response)
|
|
|
|
packet = {cmd:'write:sad', data:'data to write'}
|
|
|
|
console.log(packet)
|
|
|
|
await fio.send(packet)
|
|
|
|
packet = {cmd:'write:sad', data:'sent only via tcp'}
|
|
|
|
console.log(packet)
|
|
|
|
console.log(fio.getPacketByName('tc2',await fio.sendTCP(packet)))
|
|
|
|
packet = {cmd:'good:bad'}
|
2018-02-04 14:18:21 -08:00
|
|
|
console.log(packet)
|
|
|
|
await fio.send(packet)
|
|
|
|
|
2018-01-27 23:20:33 -08:00
|
|
|
process.kill(process.pid, 'SIGTERM')
|
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
2018-01-29 21:51:13 -08:00
|
|
|
process.kill(process.pid, 'SIGTERM')
|
2018-01-27 23:20:33 -08:00
|
|
|
})
|