soprano

1.0.34 • Public • Published

soprano

Abstract Multi-protocol Socket Library for NodeJs

Install

npm i soprano --save

Protocols

  • EchoProtocol (Built-in Echo protocol)
  • Soprano.RPCProtocol: github / npm
    • Simple RPC (Remote Procedure Call) protocol with some cool features
  • Soprano.PubSubProtocol: github / npm
    • Publish / Subscription protocol with some cool features

Examples

Basic Usage

server.js

const Soprano = require('./');
 
(async function () {
    try{
 
        // create Soprano instance
        let soprano = new Soprano({port: 3000, host: '0.0.0.0'});
 
        // create Protocol instance
        let echoProtocol = soprano.createProtocol(Soprano.EchoProtocol);
 
        // Attach some optional middleware (this is protocol specific)
        echoProtocol.use(async function (echoData, req) {
            // modify data by adding "ECHO: " prefix
            return Buffer.concat([Buffer.from("ECHO: "), echoData]);
        });
 
 
        // Bind protocol to soprano instance
        await soprano.bind(echoProtocol);
 
        // Create SopranoServer and listen on specified port
        let server = await soprano.listen();
 
        console.log("listening on %s:%s", server.host, server.port);
 
    } catch (err){
        console.log(err);
    }
})();

client.js

const Soprano = require('./');
 
(async function () {
    try{
        // create Soprano instance
        let soprano = new Soprano();
 
        // create EchoProtocol instance
        let echoProtocol = soprano.createProtocol(Soprano.EchoProtocol);
 
        // echo something and grab the server result
        let result = await echoProtocol.echo('Hello World');
 
        console.log(result);
    } catch (err){
        console.log(err);
    }
})();

Readme

Keywords

Package Sidebar

Install

npm i soprano

Weekly Downloads

1

Version

1.0.34

License

MIT

Last publish

Collaborators

  • tolgahan