mirror of
https://github.com/faye/faye-websocket-ruby.git
synced 2025-11-01 13:59:13 +00:00
Add SSL capability to examples.
This commit is contained in:
+9
-2
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user