GithubHelp home page GithubHelp logo

actortcp's Introduction

Actor TCP

Actor-tcp is lightweight, independent, async, event based, tcp interface library

Why

This package is meant to be single instance, lightweight, async and scope-full, in order to provide communication between objects in different scopes. Binding on an event, maintains the worker scope, so they can continue to process the call in a non blocking way, with the next() method.

How to Use It

The Actor boudle is single instance, so it listens and emits the same events all across your app. Just require the "actor-emitter" library, then load "actor-tcp", to add the listeners

var config = require('./config'), Mng = require('mongodb').MongoClient, emitter = require('actor-emitter');

require('actor-tcp');

var worker = function(err, db) {

    console.log('Worker connected to mongo: ' + config.paths.mongo);

    var Answers = db.collection('answers');

    emitter.trigger('tcp:connect', '127.0.0.1:34440');

    emitter.bind('tcp:open', function () {
        console.log('Client connected \nStarting streaming');
    });

    emitter.bind('c3a:store', function (msg) {

        Answers.insert(msg, function(err, data) {});
    });
};

Mng.connect(config.paths.mongo, worker);

The emitter is bound to:

emitter.trigger('tcp:connect', {});
emitter.trigger('tcp:send', {});

Incomming messages will emmit:

emitter.bind('tcp:data', handler);

Thats it.

MIT license. If you hit bugs, fill issues on github. Feel free to fork, modify and have fun with it :)

actortcp's People

Contributors

tcmiranda avatar

Watchers

 avatar  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.