Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

everything works :)

  • Loading branch information...
commit 0cead5aef83b4b595c273b8d9822352bf1b38669 1 parent 5df8c2b
@mkeen authored
View
400 examples/.rbx/fc/fc62e6d4bdc8ec5981d569e3ccbfa8e9a0ba8588
@@ -0,0 +1,400 @@
+!RBIX
+6888350013966756256
+18
+M
+1
+n
+n
+x
+10
+__script__
+i
+77
+5
+7
+0
+64
+47
+49
+1
+1
+15
+45
+2
+3
+43
+4
+44
+43
+5
+4
+4
+49
+6
+1
+13
+7
+7
+7
+8
+64
+49
+9
+2
+15
+13
+7
+10
+7
+11
+49
+9
+2
+15
+13
+7
+12
+7
+13
+64
+49
+9
+2
+15
+13
+7
+14
+7
+13
+64
+49
+9
+2
+15
+56
+15
+50
+16
+1
+15
+5
+7
+17
+47
+49
+18
+1
+15
+2
+11
+I
+5
+I
+0
+I
+0
+I
+0
+I
+0
+n
+p
+19
+s
+E
+0
+
+15
+../lib/noise.rb
+x
+7
+require
+x
+5
+Noise
+n
+x
+10
+Connection
+x
+4
+Hash
+x
+16
+new_from_literal
+x
+4
+host
+s
+E
+0
+
+9
+localhost
+x
+3
+[]=
+x
+4
+port
+I
+f0ad
+x
+4
+user
+s
+E
+0
+
+5
+guest
+x
+4
+pass
+M
+1
+p
+2
+x
+9
+for_block
+t
+n
+x
+9
+__block__
+i
+29
+5
+7
+0
+64
+47
+49
+1
+1
+15
+5
+56
+2
+47
+50
+3
+0
+15
+5
+7
+4
+64
+7
+0
+64
+47
+49
+5
+2
+11
+I
+4
+I
+0
+I
+0
+I
+0
+I
+0
+I
+-2
+p
+6
+s
+E
+0
+
+11
+/topic/mike
+x
+9
+subscribe
+M
+1
+p
+2
+x
+9
+for_block
+t
+n
+x
+9
+__block__
+i
+39
+57
+19
+0
+15
+5
+20
+0
+49
+0
+0
+7
+1
+49
+2
+1
+47
+49
+3
+1
+15
+5
+5
+7
+4
+47
+49
+5
+1
+49
+6
+0
+7
+7
+64
+47
+49
+8
+2
+11
+I
+5
+I
+1
+I
+1
+I
+0
+I
+1
+n
+p
+9
+x
+7
+to_hash
+x
+4
+body
+x
+2
+[]
+x
+4
+puts
+I
+2710
+x
+4
+rand
+x
+4
+to_s
+s
+E
+0
+
+11
+/topic/mike
+x
+4
+send
+p
+7
+I
+0
+I
+6
+I
+4
+I
+7
+I
+14
+I
+8
+I
+27
+x
+53
+/Users/michael/Desktop/Noise/examples/basic_client.rb
+p
+1
+x
+5
+frame
+x
+10
+on_message
+s
+E
+0
+
+44
+this is a test of the emergency broadcasting
+x
+4
+send
+p
+7
+I
+0
+I
+4
+I
+9
+I
+6
+I
+11
+I
+b
+I
+1d
+x
+53
+/Users/michael/Desktop/Noise/examples/basic_client.rb
+p
+0
+x
+3
+new
+I
+1388
+x
+5
+sleep
+p
+7
+I
+0
+I
+1
+I
+9
+I
+3
+I
+43
+I
+e
+I
+4d
+x
+53
+/Users/michael/Desktop/Noise/examples/basic_client.rb
+p
+0
View
10 examples/basic_client.rb
@@ -2,7 +2,13 @@
Noise::Connection.new :host => "localhost", :port => 61613, :user => "guest", :pass => "guest" do
subscribe "/topic/mike"
- send "hello", "/topic/mike"
+
+ on_message do |frame|
+ puts frame.to_hash[:body]
+ send rand(10000).to_s, "/topic/mike"
+ end
+
+ send "this is a test of the emergency broadcasting", "/topic/mike"
end
-sleep 100
+sleep 5000
View
15 lib/noise/connection.rb
@@ -67,16 +67,17 @@ def login
end
def logout
- write Noise::Frame.new :command => "disconnect"
+ write Noise::Frame.new :command => "disconect"
end
- def subscribe destination
- actor << @@out[Noise::Frame.new(:command => "subscribe", :headers => {:destination => destination})]
+ def subscribe destination, &block
+ #on_message(destination, true, &block)
+ write Noise::Frame.new :command => "subscribe", :headers => {:destination => destination}
end
def send msg, destination
#actor << @@out[Noise::Frame.new(:command => "send", :headers => {:destination => destination}, :body => msg)]
- actor << @@out[Noise::Frame.new(:command => "send", :headers => {:destination => destination}, :body => msg)]
+ write Noise::Frame.new :command => "send", :headers => {:destination => destination}, :body => msg
end
@@ -178,7 +179,7 @@ def wait
# to false at the time the subscription was created
def received_frame frame
@subscriptions[frame.to_hash[:command]].each do |proc|
- if proc.call == false
+ if proc.call(frame) == false
@subscriptions[frame.to_hash[:command]].delete proc
end
@@ -193,8 +194,8 @@ def received_frame frame
def on command, forever = true, &block
@subscriptions ||= {}
@subscriptions[command.upcase] ||= []
- @subscriptions[command.upcase] << Proc.new do
- instance_eval &block
+ @subscriptions[command.upcase] << Proc.new do |frame|
+ instance_exec frame, &block
# Return the param "forever", which was passed to "on", so that
# the received_frame method will know whether to remove the sub
# or not.
View
16 lib/noise/frame.rb
@@ -24,14 +24,18 @@ def initialize args
def from_string str
@headers = {}
@body = ""
- parse = str.split @@newline
- @command = parse.shift
- parse.each do |header|
+ parse_headers = str.split @@newline
+ @command = parse_headers.shift
+ parse_headers.delete_if do |item|
+ !item.include?(":")
+ end
+
+ parse_headers.each do |header|
split = header.split ":"
- @headers[split[0].chomp] = split[1].chomp
+ (@headers[split[0].chomp] = split[1].chomp) unless split.length < 1
end
- @body = str[-@headers["content-length"]..-1] unless !@headers.include? "content-length" or @headers["content-length"] < 1
+ @body = str[-(@headers["content-length"].to_i)..-1].chomp unless !@headers.include? "content-length" or @headers["content-length"].to_i < 1
end
# Modifies
@@ -59,7 +63,7 @@ def headers
end
def body
- @body + @@newline
+ @body + @@newline + @@newline
end
def to_s
Please sign in to comment.
Something went wrong with that request. Please try again.