markjeee / socket.io-rack Goto Github PK
View Code? Open in Web Editor NEWRack version for the Socket.IO server side (just like Socket.IO-node) -- an unofficial implementation.
Home Page: http://socket.io
License: Other
Rack version for the Socket.IO server side (just like Socket.IO-node) -- an unofficial implementation.
Home Page: http://socket.io
License: Other
*STATUS* Super alpha, super experimental, not to be used yet for real work, unless you want to hack in to the code and help me get it to production ready. :) *REQUIREMENTS* You need the following gems: * thin * redis And also a running redis installation, with at least version 2.1.3 (yes, you'll have to use the trunk version). *GOAL* Add this in your config/environment.rb in Rails, or just use the Middleware, in any Rack-compatible app. This will be implemented using Thin + EventMachine, so you're likely going to need those as well. config.middleware.use("Palmade::SocketIoRack::Middleware", { :resources => { '/firehose/socket.io' => "Tweetitow::FirehoseSocket", '/echo' => "Palmade::SocketIoRack::EchoResource" } })
Moved here from #1 for later implement.
force_encoding is only needed in ruby 1.9 - so in ruby 1.8 they can be skipped.
I created simple class for rack:
class MyClass
def self.call(data)
puts data.inspect
end
end
now when in irb I call
Rack::Handler::WEBrick.run(Palmade::SocketIoRack::Middleware.new(MyApp.new, :resources => {'/' => "Palmade::SocketIoRack::EchoResource"}), :Port => 8080)
and try to connect with WebSocket client it throws error:
{"HTTP_HOST"=>"127.0.0.1:8080", "SERVER_NAME"=>"127.0.0.1", "REQUEST_PATH"=>"/", "rack.url_scheme"=>"http", "REMOTE_HOST"=>"imanel.local", "rack.errors"=>#<IO:0x100183b88>, "SERVER_PROTOCOL"=>"HTTP/1.1", "rack.version"=>[1, 1], "rack.run_once"=>false, "SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/1.8.7/2009-06-12)", "REMOTE_ADDR"=>"127.0.0.1", "PATH_INFO"=>"/", "HTTP_SEC_WEBSOCKET_KEY1"=>"]+ *1 91 D4 2 32959", "SCRIPT_NAME"=>"", "HTTP_VERSION"=>"HTTP/1.1", "rack.multithread"=>true, "HTTP_SEC_WEBSOCKET_KEY2"=>"S2%0O 80FL4 9 949", "rack.multiprocess"=>false, "REQUEST_URI"=>"http://127.0.0.1:8080/?client_id=", "SERVER_PORT"=>"8080", "REQUEST_METHOD"=>"GET", "HTTP_UPGRADE"=>"WebSocket", "HTTP_ORIGIN"=>"http://localhost:3000", "rack.input"=>#<StringIO:0x1023f4c58>, "HTTP_CONNECTION"=>"Upgrade", "QUERY_STRING"=>"client_id=", "GATEWAY_INTERFACE"=>"CGI/1.1"}
[2010-09-12 10:08:13] ERROR NoMethodError: undefined method `each' for nil:NilClass
/opt/local/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/utils.rb:273:in `initialize'
/opt/local/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/utils.rb:267:in `new'
/opt/local/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/utils.rb:267:in `new'
/opt/local/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/content_length.rb:14:in `call'
/opt/local/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/handler/webrick.rb:48:in `service'
/opt/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/opt/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/opt/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/opt/local/lib/ruby/1.8/webrick/server.rb:162:in `start'
/opt/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/opt/local/lib/ruby/1.8/webrick/server.rb:95:in `start'
/opt/local/lib/ruby/1.8/webrick/server.rb:92:in `each'
/opt/local/lib/ruby/1.8/webrick/server.rb:92:in `start'
/opt/local/lib/ruby/1.8/webrick/server.rb:23:in `start'
/opt/local/lib/ruby/1.8/webrick/server.rb:82:in `start'
/opt/local/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/handler/webrick.rb:14:in `run'
(irb):18:in `irb_binding'
/opt/local/lib/ruby/1.8/irb/workspace.rb:52:in `irb_binding'
/opt/local/lib/ruby/1.8/irb/workspace.rb:52
imanel.local - - [12/Sep/2010:10:08:13 CEST] "GET /?client_id= HTTP/1.1" 500 320
- -> /?client_id=
I used WEBrick because it gives more info(thin fails at the same point). Do you know what's the problem? System: OS X 10.6.4, ruby 1.8.7.174(i686)
127.0.0.1 - - [13/Sep/2010 17:16:14] "GET /firehose/xhr-multipart/ HTTP/1.1" -1 - 0.0240
127.0.0.1 - - [13/Sep/2010 17:17:51] "GET /firehose/xhr-polling//1284391071124 HTTP/1.1" -1 - 0.0012
WebSockets if working, but both xhr are failing(Firebug shows response 200 but in read - no data received) I don't yet familiar enough with your code to know what could went wrong, but it happens both on 1.8.7 and 1.9.2 so I think that you could know something.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.