Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

project stub with basic rev infrastructure

  • Loading branch information...
commit d9aaaebd1ffc3325bf4450745e68f1ff29d9176b 0 parents
@substack authored
3  README.md
@@ -0,0 +1,3 @@
+Implements the DNode protocol for ruby.
+
+See the [node.js dnode project](http://github.com/substack/dnode) for more info.
24 dnode.rb
@@ -0,0 +1,24 @@
+require './dnode/conn.rb'
+require 'rev'
+
+class DNode
+ def initialize obj={}
+ @object = obj
+ end
+
+ def connect *args, &block
+ types = args.inject({}) { |acc,x| acc.merge(x.class.to_s => x) }
+ host = types['String'] || 'localhost'
+ port = types['Fixnum']
+
+ event_loop = Rev::Loop.default
+ Conn.connect(host, port).attach(event_loop)
+ event_loop.run
+ end
+
+ def listen
+ event_loop = Rev::Loop.default
+ Rev::TCPServer.new(host, port, Conn).attach(event_loop)
+ event_loop.run
+ end
+end
17 dnode/conn.rb
@@ -0,0 +1,17 @@
+require 'rev'
+require 'events'
+
+class Conn < Rev::TCPSocket
+ include Events::Emitter
+
+ def on_connect
+ puts 'connect!'
+ end
+
+ def on_close
+ end
+
+ def on_read data
+ puts "data = #{data}"
+ end
+end
3  dnode/scrub.rb
@@ -0,0 +1,3 @@
+class Scrub
+
+end
2  dnode/walk.rb
@@ -0,0 +1,2 @@
+class Walk
+end
Please sign in to comment.
Something went wrong with that request. Please try again.