Added ssl support.

This commit is contained in:
Martin Edenhofer 2012-08-02 11:17:22 +02:00
parent 3500391208
commit 0e938ffb2e

View file

@ -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 {