-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
142 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source "https://rubygems.org" | ||
|
||
#gem "em-websocket" | ||
gem "em-websocket", "0.3.8" | ||
gem "goliath" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
addressable (2.3.3) | ||
async-rack (0.5.1) | ||
rack (~> 1.1) | ||
em-synchrony (1.0.3) | ||
eventmachine (>= 1.0.0.beta.1) | ||
em-websocket (0.3.8) | ||
addressable (>= 2.1.1) | ||
eventmachine (>= 0.12.9) | ||
eventmachine (1.0.3) | ||
goliath (1.0.1) | ||
async-rack | ||
em-synchrony (>= 1.0.0) | ||
em-websocket | ||
eventmachine (>= 1.0.0.beta.4) | ||
http_parser.rb (= 0.5.3) | ||
log4r | ||
multi_json | ||
rack (>= 1.2.2) | ||
rack-contrib | ||
rack-respond_to | ||
http_parser.rb (0.5.3) | ||
log4r (1.1.10) | ||
multi_json (1.7.2) | ||
rack (1.5.2) | ||
rack-accept-media-types (0.9) | ||
rack-contrib (1.1.0) | ||
rack (>= 0.9.1) | ||
rack-respond_to (0.9.8) | ||
rack-accept-media-types (>= 0.6) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
em-websocket (= 0.3.8) | ||
goliath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
ruby-websocket | ||
============== | ||
#ruby-websocket | ||
ruby websocket connection test | ||
|
||
ruby websocket connection test | ||
###with em-websocket 0.5.0 | ||
bundle exec ruby websocket.rb | ||
|
||
###with em-websocket 0.3.8 | ||
bundle exec ruby websocket_old.rb | ||
bundle exec ruby goliath_websocket.rb -e prod -sv -p 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
if ("WebSocket" in window) { | ||
var ws = new WebSocket("ws://localhost:8080/ws"); | ||
ws.onmessage = function(evt) { }; | ||
ws.onclose = function() { }; | ||
ws.onopen = function() { }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
config['channel'] = EM::Channel.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'goliath' | ||
require 'goliath/websocket' | ||
|
||
class Websocket < Goliath::WebSocket | ||
|
||
def on_open(env) | ||
env.logger.info("WS OPEN") | ||
end | ||
|
||
def on_message(env, msg) | ||
env.logger.info("WS MESSAGE: #{msg}") | ||
end | ||
|
||
def on_close(env) | ||
env.logger.info("WS CLOSED") | ||
end | ||
|
||
def on_error(env, error) | ||
env.logger.error error | ||
end | ||
|
||
def response(env) | ||
super(env) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<html> | ||
<head> | ||
<script> | ||
function init() { | ||
function debug(string) { | ||
var element = document.getElementById("debug"); | ||
var p = document.createElement("p"); | ||
p.appendChild(document.createTextNode(string)); | ||
element.appendChild(p); | ||
} | ||
|
||
var Socket = "MozWebSocket" in window ? MozWebSocket : WebSocket; | ||
var ws = new Socket("ws://localhost:8080/foo/bar?hello=world"); | ||
ws.onmessage = function(evt) { debug("Received: " + evt.data); }; | ||
ws.onclose = function(event) { | ||
debug("Closed - code: " + event.code + ", reason: " + event.reason + ", wasClean: " + event.wasClean); | ||
}; | ||
ws.onopen = function() { | ||
debug("connected..."); | ||
ws.send("hello server"); | ||
ws.send("hello again"); | ||
}; | ||
}; | ||
</script> | ||
</head> | ||
<body onload="init();"> | ||
<div id="debug"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'em-websocket' | ||
|
||
# only em-websocket 0.5.0 | ||
EM.run { | ||
EM::WebSocket.run(:host => "0.0.0.0", :port => 8080, :debug => false) do |ws| | ||
ws.onopen { |handshake|puts "WebSocket opened #{{ | ||
:path => handshake.path, | ||
:query => handshake.query, | ||
:origin => handshake.origin, | ||
}}" | ||
} | ||
ws.onmessage { |msg| ws.send "Pong: #{msg}" } | ||
ws.onclose { puts "WebSocket closed" } | ||
ws.onerror { |e| puts "Error: #{e.message}" } | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'em-websocket' | ||
|
||
# em-websocket 0.3.8 & 0.5.0 | ||
EventMachine.run do | ||
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080) do |ws| | ||
ws.onopen { |handshake| puts "WebSocket opened" } | ||
ws.onmessage { |msg| ws.send "Pong: #{msg}" } | ||
ws.onclose { puts "WebSocket closed" } | ||
ws.onerror { |e| puts "Error: #{e.message}" } | ||
end | ||
end |