diff --git a/lib/websocket-client-simple/client.rb b/lib/websocket-client-simple/client.rb index 128f523..9d208d2 100644 --- a/lib/websocket-client-simple/client.rb +++ b/lib/websocket-client-simple/client.rb @@ -14,7 +14,7 @@ class Client attr_reader :url, :handshake def connect(url, options={}) - return if @socket + return if @socket ||= nil @url = url uri = URI.parse url @socket = TCPSocket.new(uri.host, @@ -84,11 +84,16 @@ def close if !@pipe_broken send nil, :type => :close end + @closed = true + if @thread + Thread.kill @thread + Thread.pass while @thread.status + @thread = nil + end @socket.close if @socket @socket = nil emit :__close - Thread.kill @thread if @thread end def open?