Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added to use SNI #36

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ DEPENDENCIES
websocket-eventmachine-server

BUNDLED WITH
1.11.2
1.17.3
12 changes: 11 additions & 1 deletion lib/websocket-client-simple/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ def self.connect(url, options={})

class Client
include EventEmitter
attr_reader :url, :handshake
attr_reader :url, :handshake, :message

def connect(url, options={})
return if @socket
@url = url
uri = URI.parse url
@socket = TCPSocket.new(uri.host,
uri.port || (uri.scheme == 'wss' ? 443 : 80))
@socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
if ['https', 'wss'].include? uri.scheme
ctx = OpenSSL::SSL::SSLContext.new
ctx.ssl_version = options[:ssl_version] || 'SSLv23'
Expand All @@ -27,6 +28,7 @@ def connect(url, options={})
cert_store.set_default_paths
ctx.cert_store = cert_store
@socket = ::OpenSSL::SSL::SSLSocket.new(@socket, ctx)
@socket.hostname = uri.host
@socket.connect
end
@handshake = ::WebSocket::Handshake::Client.new :url => url, :headers => options[:headers]
Expand Down Expand Up @@ -55,6 +57,7 @@ def connect(url, options={})
else
frame << recv_data
while msg = frame.next
@message = msg
emit :message, msg
end
end
Expand All @@ -76,6 +79,9 @@ def send(data, opt={:type => :text})
rescue Errno::EPIPE => e
@pipe_broken = true
emit :__close, e
rescue OpenSSL::SSL::SSLError => e
@pipe_broken = true
emit :__close, e
end
end

Expand All @@ -95,6 +101,10 @@ def open?
@handshake.finished? and !@closed
end

def close?
@closed
end

end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/websocket-client-simple/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module WebSocket
module Client
module Simple
VERSION = "0.3.0"
VERSION = "0.3.4"
end
end
end
12 changes: 6 additions & 6 deletions websocket-client-simple.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "minitest"
spec.add_development_dependency "websocket-eventmachine-server"
spec.add_development_dependency "eventmachine"
spec.add_development_dependency "rake", "~> 12.3.2"
spec.add_development_dependency "minitest", "~> 5.11.3"
spec.add_development_dependency "websocket-eventmachine-server", ">= 0"
spec.add_development_dependency "eventmachine", "~> 1.2.7"

spec.add_dependency "websocket"
spec.add_dependency "event_emitter"
spec.add_dependency "websocket", "~> 1.2.8"
spec.add_dependency "event_emitter", "~> 0.2.6"
end