const { Endpoint } = require('simple-rpc-protocol')
const net = require('net')
net.createServer(socket => {
const endpoint = new Endpoint()
endpoint.command('shout', {
oncall (args, channel) {
channel.reply(args[0].toUpperCase())
}
})
endpoint.command('shoutstream', {
mode: 'streaming'
oncall (args, channel) {
channel.pipe(new Transform({
transform (chunk, enc, next) {
this.push(chunk.toUpperCase())
}
}).pipe(channel)
}
}))
socket.pipe(endpoint).pipe(socket)
endpoint.announce()
}).listen(8000)
const { Endpoint } = require('simple-rpc-protocol')
const net = require('net')
const socket = net.connect(8000)
const endpoint = new Endpoint()
endpoint.pipe(socket).pipe(endoint)
const uppercased = await endpoint.call('echo', ['hello'])
const channel = endpoint.callStream('shoutstream')
process.stdin.pipe(channel).pipe(process.stdout)