Giter VIP home page Giter VIP logo

simple-rpc-protocol's Introduction

simple-rpc-protocol

A simple RPC protocol that uses simple-message-channels as wire protocol.

Supports routing between different endpoints and fast binary messaging.

Examples

See test.js and shoutstream-example.js for now.

Usage

// server.js
// provide a command
const { Endpoint } = require('simple-rpc-protocol')
const net = require('net')
// pipe the transport stream into any binary stream
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)

// client.js
// at the other end of the stream:
const { Endpoint } = require('simple-rpc-protocol')
const net = require('net')
const socket = net.connect(8000)
const endpoint = new Endpoint()
endpoint.pipe(socket).pipe(endoint)

// Call an async command.
const uppercased = await endpoint.call('echo', ['hello'])
// uppercased === 'HELLO'

// Call a streaming command.
const channel = endpoint.callStream('shoutstream')
process.stdin.pipe(channel).pipe(process.stdout)

simple-rpc-protocol's People

Contributors

frando avatar

Stargazers

René Jochum avatar Byron Jones avatar Diego avatar  avatar Joseph Werle avatar Andrew Chou avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.