GitXplorerGitXplorer
u

distobj

public
0 stars
1 forks
0 issues

Commits

List of commits on branch master.
Unverified
b9879d279bca57b09ebe203cb02976a67219e11e

inc version

uunixpickle committed 11 years ago
Unverified
b4ba463e0a41acaafbafe3f13d1b10a46363e055

handle errors on server better

uunixpickle committed 11 years ago
Unverified
c9969b1bcf113e34959222ece67e9ee6ef9a92c1

ignore private methods (e.g. _method)

uunixpickle committed 11 years ago
Unverified
3395bbea443cb7f8a34e426eec4f49840fae7c94

fix encoding null issue

committed 11 years ago
Unverified
69d1dc6bb6511a5cfc3b871df32886cca10ca047

updated repository field

uunixpickle committed 11 years ago
Unverified
259710ce6f8d0fffba34cdb54af7852745893283

fixed package

uunixpickle committed 11 years ago

README

The README file for this repository.

Distributed Objects in Node.js

distobj provides a basic facility for accessing remote EventEmitters over the network in Node.js. Internally, distobj uses JSON to encode arguments you pass, and to encode responses (which come in the form of events). Since Node.js is totally event based, distobj has no concept of return values.

Usage

You can create and publish an object as follows in this CoffeeScript example:

{Emitter, Server} = require 'distobj'
net = require 'net'

# simply subclass the Emitter class
class TestObject extends Emitter
  print: (data) ->
    console.log data
    # events we emit are broadcasted
    @emit 'echo', data
  add: (a, b) ->
    @emit 'sum', a + b

# create a new TestObject.
object = new TestObject()
# create a server with object on port 1337.
server = net.createServer()
realObj = new Server server, object
server.listen 1337

To access that object from a different process, do this:

{Client} = require 'distobj'
net = require 'net'
# create a connection
socket = net.connect port: 1337, ->
  # create a client and await a callback
  c = new Client socket, ->
    # upon receiving this callback, the client is now configured
    # with all of the methods on the remote object
    c.add 10, 20
    c.print 'hey there'
  # treat c like a normal event emitter
  c.on 'sum', (n) ->
    console.log 'got sum: ' + n
  c.on 'echo', (d) ->
    console.log 'got echo: ' + d

As you can see, distobj makes it almost too easy to access objects over the network!