This package has been deprecated

    Author message:

    Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

    tiny-socket

    0.0.2 • Public • Published

    tiny-socket

    A tiny wrapper for Node's sockets, written in ES7.

    Usage

    The most convenient way of using this module is with ES7's async/await.

     
        (async function(){
     
            let server;
            try { server = await new Conn.Server(); } catch (err){ throw new Error(err); }
     
            server.onData = function(data){
                console.info('server » data »', data);
                server.send({test:'hello back'});
                server.close();
            };
            server.onOpen = function(){
                console.info('server » client opened connection');
            };
            server.onClose = function(){
                console.info('server » connection closed')
            }
     
            let client;
            try { client = await new Conn.Client(); } catch (err){ throw new Error(err); }
     
            client.onData = function(data){
                console.info('client » data »', data);
            };
     
            client.send({test:'hello world'});
     
        })();
     

    But if you don't feel comfortable using this syntax, you can use regular promises

     
        let TinySocket = require('tiny-socket');
     
        (new TinySocket.Server()).then(function(server, err){
            if (err) throw err;
            server.onData = function(data){
                console.info('server » data »', data);
                server.send({test:'hello back'});
                server.close();
            };
            server.onOpen = function(){
                console.info('server » client opened connection');
            };
            server.onClose = function(){
                console.info('server » connection closed')
            }
            return new TinySocket.Client();
        }).then(function(client, err){
            if (err) throw err;
            client.onData = function(data){
                console.info('client » data »', data);
            };
            client.send({test:'hello world'});
        }).catch(function(err){
            server.close();
            throw err;
        });
     

    Install

    npm i tiny-socket

    DownloadsWeekly Downloads

    2

    Version

    0.0.2

    License

    MIT

    Last publish

    Collaborators

    • etor