Permalink
Browse files

Merge pull request #7 from kkiselev/master

cowboy_websocket_rack_handler
  • Loading branch information...
2 parents 2afca63 + edb247e commit b4957327470faf3fe4e312222094e6ddd614ef66 @maxlapshin maxlapshin committed Jul 29, 2013
Showing with 20,201 additions and 90 deletions.
  1. +0 −2 example-app/Makefile
  2. +32 −0 example-app/README.md
  3. +2 −0 example-app/change_max_files.sh
  4. +45 −0 example-app/cli.rb
  5. +17,720 −0 example-app/erl_crash.dump
  6. +15 −0 example-app/priv/.gitignore
  7. +40 −0 example-app/priv/Gemfile
  8. +121 −0 example-app/priv/Gemfile.lock
  9. +261 −0 example-app/priv/README.rdoc
  10. +7 −0 example-app/priv/Rakefile
  11. BIN example-app/priv/app/assets/images/rails.png
  12. +15 −0 example-app/priv/app/assets/javascripts/application.js
  13. +3 −0 example-app/priv/app/assets/javascripts/main.js.coffee
  14. +13 −0 example-app/priv/app/assets/stylesheets/application.css
  15. +3 −0 example-app/priv/app/assets/stylesheets/main.css.scss
  16. +3 −0 example-app/priv/app/controllers/application_controller.rb
  17. +45 −0 example-app/priv/app/controllers/main_controller.rb
  18. +2 −0 example-app/priv/app/helpers/application_helper.rb
  19. +2 −0 example-app/priv/app/helpers/main_helper.rb
  20. 0 example-app/priv/app/mailers/.gitkeep
  21. 0 example-app/priv/app/models/.gitkeep
  22. +14 −0 example-app/priv/app/views/layouts/application.html.erb
  23. +2 −0 example-app/priv/app/views/main/index.html.erb
  24. +4 −0 example-app/priv/config.ru
  25. +62 −0 example-app/priv/config/application.rb
  26. +6 −0 example-app/priv/config/boot.rb
  27. +25 −0 example-app/priv/config/database.yml
  28. +7 −0 example-app/priv/config/environment.rb
  29. +37 −0 example-app/priv/config/environments/development.rb
  30. +67 −0 example-app/priv/config/environments/production.rb
  31. +37 −0 example-app/priv/config/environments/test.rb
  32. +7 −0 example-app/priv/config/initializers/backtrace_silencers.rb
  33. +15 −0 example-app/priv/config/initializers/inflections.rb
  34. +5 −0 example-app/priv/config/initializers/mime_types.rb
  35. +7 −0 example-app/priv/config/initializers/secret_token.rb
  36. +8 −0 example-app/priv/config/initializers/session_store.rb
  37. +14 −0 example-app/priv/config/initializers/wrap_parameters.rb
  38. +5 −0 example-app/priv/config/locales/en.yml
  39. +61 −0 example-app/priv/config/routes.rb
  40. +7 −0 example-app/priv/db/seeds.rb
  41. +2 −0 example-app/priv/doc/README_FOR_APP
  42. 0 example-app/priv/lib/assets/.gitkeep
  43. 0 example-app/priv/lib/tasks/.gitkeep
  44. 0 example-app/priv/log/.gitkeep
  45. +26 −0 example-app/priv/public/404.html
  46. +26 −0 example-app/priv/public/422.html
  47. +25 −0 example-app/priv/public/500.html
  48. 0 example-app/priv/public/favicon.ico
  49. BIN example-app/priv/public/picture_ololo.png
  50. +5 −0 example-app/priv/public/robots.txt
  51. +6 −0 example-app/priv/script/rails
  52. 0 example-app/priv/test/fixtures/.gitkeep
  53. 0 example-app/priv/test/functional/.gitkeep
  54. +9 −0 example-app/priv/test/functional/main_controller_test.rb
  55. 0 example-app/priv/test/integration/.gitkeep
  56. +12 −0 example-app/priv/test/performance/browsing_test.rb
  57. +13 −0 example-app/priv/test/test_helper.rb
  58. 0 example-app/priv/test/unit/.gitkeep
  59. +4 −0 example-app/priv/test/unit/helpers/main_helper_test.rb
  60. 0 example-app/priv/vendor/assets/javascripts/.gitkeep
  61. 0 example-app/priv/vendor/assets/stylesheets/.gitkeep
  62. 0 example-app/priv/vendor/plugins/.gitkeep
  63. +3 −7 example-app/rebar.config
  64. +2 −2 example-app/run
  65. +13 −0 example-app/src/echo_event_manager.erl
  66. +15 −0 example-app/src/echo_get.app.src
  67. +16 −0 example-app/src/echo_get.erl
  68. +32 −0 example-app/src/echo_get_app.erl
  69. +23 −0 example-app/src/echo_get_sup.erl
  70. +96 −0 example-app/src/echo_handler.erl
  71. +0 −12 example-app/src/example_rack.app.src
  72. +0 −26 example-app/src/example_rack.erl
  73. BIN example-app/src/mochijson2.beam
  74. +29 −0 example-app/src/toppage_handler.erl
  75. +4 −0 example-app/start.sh
  76. +5 −0 example-app/start_detached.sh
  77. +6 −6 priv/worker.rb
  78. +38 −25 src/cowboy_rack_handler.erl
  79. +151 −0 src/cowboy_websocket_rack_handler.erl
  80. +889 −0 src/mochijson2.erl
  81. +7 −3 src/rack.erl
  82. +3 −3 src/rack_manager.erl
  83. +22 −4 src/rack_worker.erl
View
@@ -1,2 +0,0 @@
-all:
- [ -d ../../cowboy ] && erl -make || (../rebar get-deps && ../rebar compile)
View
@@ -0,0 +1,32 @@
+Cowboy GET Echo
+===============
+
+To compile this example you need rebar in your PATH.
+
+Type the following command:
+```
+$ rebar get-deps compile
+```
+
+You can then start the Erlang node with the following command:
+```
+./start.sh
+```
+
+Then point your browser to the indicated URL. You can change
+the GET parameter to check that the handler is echoing properly.
+
+Example
+-------
+
+``` bash
+$ curl -i "http://localhost:8080/?echo=saymyname"
+HTTP/1.1 200 OK
+connection: keep-alive
+server: Cowboy
+date: Fri, 28 Sep 2012 04:09:04 GMT
+content-length: 9
+Content-Encoding: utf-8
+
+saymyname
+```
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+sudo launchctl limit maxfiles 4096 8192
View
@@ -0,0 +1,45 @@
+#!/usr/bin/env ruby
+
+# $LOAD_PATH << File.dirname(__FILE__) + "/lib"
+# require 'web_socket'
+
+require 'websocket-eventmachine-client'
+require 'json'
+
+@ws_host = ARGV[0]
+@ws_port = ARGV[1].to_i
+
+EM.run do
+ ws = WebSocket::EventMachine::Client.connect(:uri => "ws://#{@ws_host}:#{@ws_port}/ws")
+
+ ws.onopen do
+ puts "Connected"
+
+ ts = Time.now.to_i
+ msg = {
+ "unique" => "a1s2d3f4g5h6j7k8l9",
+ "ts" => ts,
+ "action" => "main/index.json",
+ "query_str" => "",
+ "method" => "GET"
+ }
+
+ puts "Sending..."
+ # ws.send("OLOLOLOLOLO")
+ ws.send(msg.to_json)
+ end
+
+ ws.onmessage do |msg, type|
+ begin
+ json = JSON.parse(msg)
+ puts "Received JSON:\n#{json.to_s}\n"
+ rescue
+ puts "Class:#{msg.class}\nType:#{type}\nReceived message:\n#{msg}\n"
+ end
+ end
+
+ ws.onclose do
+ puts "Disconnected"
+ end
+
+end
Oops, something went wrong.

0 comments on commit b495732

Please sign in to comment.