Add SSL capability to examples.

This commit is contained in:
James Coglan
2011-11-22 19:05:20 +00:00
parent 443a0cb356
commit 87cd1e875f
2 changed files with 21 additions and 5 deletions
+9 -2
View File
@@ -1,10 +1,17 @@
require 'rubygems'
require File.expand_path('../../lib/faye/websocket', __FILE__)
require 'eventmachine'
port = ARGV[0] || 7000
port = ARGV[0] || 7000
secure = ARGV[1] == 'ssl'
EM.run {
socket = Faye::WebSocket::Client.new("ws://localhost:#{port}/")
scheme = secure ? 'wss' : 'ws'
url = "#{scheme}://localhost:#{port}/"
puts "Connecting to #{url}"
socket = Faye::WebSocket::Client.new(url)
socket.onopen = lambda do |event|
p [:open]
+12 -3
View File
@@ -1,9 +1,10 @@
require 'rubygems'
require File.expand_path('../../lib/faye/websocket', __FILE__)
require 'rack'
require 'thin'
require 'eventmachine'
port = ARGV[0] || 7000
port = ARGV[0] || 7000
secure = ARGV[1] == 'ssl'
app = lambda do |env|
if env['HTTP_UPGRADE']
@@ -26,6 +27,14 @@ end
EM.run {
thin = Rack::Handler.get('thin')
thin.run(app, :Port => port)
thin.run(app, :Port => port) do |server|
if secure
server.ssl = true
server.ssl_options = {
:private_key_file => File.expand_path('../../spec/server.key', __FILE__),
:cert_chain_file => File.expand_path('../../spec/server.crt', __FILE__)
}
end
end
}