Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Commit

Permalink
Merge d83b7dd into 05a0fca
Browse files Browse the repository at this point in the history
  • Loading branch information
slivu committed Apr 5, 2013
2 parents 05a0fca + d83b7dd commit 782e133
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
11 changes: 9 additions & 2 deletions examples/server-sent-events.rb
Expand Up @@ -15,7 +15,6 @@
run lambda { |env|
body = Reel::EventStream.new do |socket|
Connections << socket
socket.on_error { Connections.delete socket }
end
[200, {'Content-Type' => 'text/event-stream'}, body]
}
Expand All @@ -25,7 +24,15 @@
run lambda { |env|
msg = env['PATH_INFO'].gsub(/\/+/, '').strip
msg = Time.now if msg.empty?
Connections.each { |s| s.data msg }

Connections.each do |s|
begin
s.data(msg)
rescue => SocketError
Connections.delete(s)
end
end

[200, {'Content-Type' => 'text/html'}, ["Sent \"#{msg}\" to #{Connections.size} clients"]]
}
end
Expand Down
19 changes: 16 additions & 3 deletions examples/websocket-wall.rb
Expand Up @@ -14,10 +14,15 @@
map '/subscribe' do
run lambda { |env|
if socket = env['rack.websocket']

socket.on_message do |m|
socket << "Server got \"#{m}\" message"
begin
socket << 'Server got "%s" message' % m
rescue => SocketError
Connections.delete(socket)
end
end
socket.on_error { Connections.delete socket }

Connections << socket
socket.read_every 1
end
Expand All @@ -29,7 +34,15 @@
run lambda { |env|
msg = env['PATH_INFO'].gsub(/\/+/, '').strip
msg = Time.now if msg.empty?
Connections.each { |s| s << msg }

Connections.each do |s|
begin
s << msg
rescue => SocketError
Connections.delete(s)
end
end

[200, {'Content-Type' => 'text/html'}, ["Sent \"#{msg}\" to #{Connections.size} clients"]]
}
end
Expand Down

0 comments on commit 782e133

Please sign in to comment.