From 0e938ffb2e18eef9f8cffb32a4d3f444b8a47798 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 2 Aug 2012 11:17:22 +0200 Subject: [PATCH] Added ssl support. --- script/websocket-server.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/script/websocket-server.rb b/script/websocket-server.rb index 0b616162e..31d09bc38 100644 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -11,6 +11,9 @@ require 'optparse' options = { :p => 6042, :b => '0.0.0.0', + :s => false, + :k => '/path/to/server.key', + :c => '/path/to/server.crt', } OptionParser.new do |opts| opts.banner = "Usage: websocket-server.rb [options]" @@ -21,13 +24,26 @@ OptionParser.new do |opts| opts.on("-b", "--bind [OPT]", "bind address") do |b| options[:b] = b end + opts.on("-s", "--secure", "enable secure connections") do |s| + options[:s] = s + end + opts.on("-k", "--private-key [OPT]", "/path/to/server.key for secure connections") do |k| + options[:k] = k + end + opts.on("-c", "--certificate [OPT]", "/path/to/server.crt for secure connections") do |c| + options[:c] = c + end end.parse! -puts "Starting websocket server on #{ options[:b] }:#{ options[:p] }" +puts "Starting websocket server on #{ options[:b] }:#{ options[:p] } (secure:#{ options[:s].to_s })" +#puts options.inspect @clients = {} EventMachine.run { - EventMachine::WebSocket.start( :host => options[:b], :port => options[:p] ) do |ws| + EventMachine::WebSocket.start( :host => options[:b], :port => options[:p], :secure => options[:s], :tls_options => { + :private_key_file => options[:p], + :cert_chain_file => options[:c], + }) do |ws| # register client connection ws.onopen {