c9/remoteagent-protocol — Issue #2: feature-request: release all functions
Author: guybrush
Created: 2012-02-24 01:48:16+00:00
State: open

what i want to do:

``` javascript
var rap = require('remoteagent-protocol')
var net = require('net')
var l = console.log
var port = ~~(Math.random()*50000)+10000
var server = net.createServer(function(s){
l('S> C connected')
var r = new rap.Remote(s,s,0)
s.on('end',function(){
l('S> C disconnected')
// here is where we need to release all functions
})
r.emitRemote('init',{name:function(cb){cb('server')}})
r.once('init',function(fns){
setInterval(function(){
// this will Error once the client has disconnected
// (ie. we cant write to the socket anymore)
fns.name(function(n){l('S> remote-name: '+n)})
},1000)
})
})
server.listen(port,function(){
l('S> listening')
var client = net.connect(port,function(){
var r = new rap.Remote(client,client,1)
r.emitRemote('init',{name:function(cb){cb('client')}})
r.once('init',function(fns){
fns.name(function(n){
l('C> remote-name: '+n)
setTimeout(function(){client.end()},1000)
})
})
})
})
```