Permalink
Browse files

README, minor tweaks

  • Loading branch information...
1 parent 4327089 commit b6a34d1bb917fb152a1ad0ff1636f855fa9b67c1 @winton committed Jan 17, 2011
Showing with 86 additions and 11 deletions.
  1. +73 −0 README.md
  2. +1 −1 bin/puggernaut
  3. +0 −1 lib/puggernaut.rb
  4. +4 −4 lib/puggernaut/client.rb
  5. +8 −5 lib/puggernaut/server.rb
View
@@ -10,4 +10,77 @@ Requirements
<pre>
gem install puggernaut
+</pre>
+
+How it works
+------------
+
+Puggernaut consists of three pieces:
+
+* TCP client to send push messages
+* TCP server to receive push messages
+* HTTP server to deliver long poll requests
+
+Start it up
+-----------
+
+Run the <code>puggernaut</code> binary with optional port numbers:
+
+<pre>
+puggernaut &lt;http port&gt; &lt;tcp port&gt;
+</pre>
+
+The default HTTP and TCP ports are 8000 and 8001, respectively.
+
+Send push messages
+------------------
+
+<pre>
+require 'puggernaut'
+
+client = Puggernaut::Client.new("localhost:8001", "localhost:9001")
+client.push :channel => "message"
+client.push :channel => [ "message 1", "message 2" ], :channel_2 => "message"
+</pre>
+
+The <code>Client.new</code> initializer accepts any number of TCP server addresses.
+
+Set up proxy pass
+-----------------
+
+You will need to set up a URL on your public facing web server that points to the Puggernaut HTTP server.
+
+If you do not see your web server below, [Google](http://google.com) is your friend.
+
+### Apache
+
+*http.conf*
+
+<pre>
+ProxyPass /long_poll http://localhost:8000
+ProxyPassReverse /long_poll http://localhost:8000
+</pre>
+
+### Nginx
+
+*nginx.conf*
+
+<pre>
+location /long_poll {
+ proxy_pass http://localhost:8000
+}
+</pre>
+
+Receive push messages
+---------------------
+
+Add [puggernaut.js](/winton/puggernaut/public/puggernaut.js) to your HTML page.
+
+Javascript client example:
+
+<pre>
+var pug = Puggernaut('/long_poll');
+pug.pull('channel', function(message) {
+ // do something with message here
+});
</pre>
View
@@ -2,4 +2,4 @@
require File.expand_path(File.dirname(__FILE__) + "/../lib/puggernaut")
-Puggernaut::Server.new(*[ ARGV[0] ? ARGV[0].to_i : nil ].compact)
+Puggernaut::Server.new(*ARGV)
View
@@ -13,5 +13,4 @@
require 'puggernaut/server'
module Puggernaut
- # snort snort
end
@@ -7,10 +7,10 @@ class Client
attr_accessor :connections
- def initialize(servers={})
+ def initialize(*servers)
@connections = {}
@retry = []
- @servers = servers
+ @servers = servers.collect { |s| s.split(':') }
end
def close
@@ -20,15 +20,15 @@ def close
end
end
- def say(messages)
+ def push(messages)
messages.each do |room, message|
message =
if message.is_a?(::Array)
message.collect { |m| "#{room}|#{m}" }.join("\n")
else
"#{room}|#{message}"
end
- @servers.each do |host, port|
+ @servers.each do |(host, port)|
send host, port, message
end
end
@@ -11,18 +11,21 @@ class <<self
attr_accessor :rooms
end
- def initialize(port=8000)
+ def initialize(http_port=8000, tcp_port=http_port+1)
+ puts "Puggernaut is starting on #{http_port} (HTTP) and #{tcp_port} (TCP)"
+ puts "*snort*"
+
loop do
begin
GC.start
self.class.rooms = {}
EM.epoll if EM.epoll?
EM.run do
- logger.info "Server#initialize - Starting HTTP - #{port}"
- EM.start_server '0.0.0.0', port, Http
+ logger.info "Server#initialize - Starting HTTP - #{http_port}"
+ EM.start_server '0.0.0.0', http_port, Http
- logger.info "Server#initialize - Starting TCP - #{port+1}"
- EM.start_server '0.0.0.0', port + 1, Tcp
+ logger.info "Server#initialize - Starting TCP - #{tcp_port}"
+ EM.start_server '0.0.0.0', tcp_port, Tcp
end
rescue Interrupt
logger.info "Server#initialize - Shutting down"

0 comments on commit b6a34d1

Please sign in to comment.