uci-socket/examples/server.mjs

37 lines
728 B
JavaScript
Raw Normal View History

import { Socket } from '../src'
const USOCKET = '/opt/sockets/samplecs.sock'
;
(async () => {
class Test {
constructor() {
this.socket = new Socket(USOCKET)
}
async processPacket(packet) {
console.log('packet being processed')
console.dir(packet)
return await this[packet.cmd](packet.data,packet.name)
}
async doit(data,name) {
let res = {}
console.log('data:', data)
res.status ='success'
res.name = name
res.data = 'this would be response from device'
return(res)
}
init() { this.socket.create(this)}
}
let test = new Test()
await test.init()
})().catch(err => {
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
})