Class: WebSocketIO::Client
- Inherits:
-
Object
- Object
- WebSocketIO::Client
- Extended by:
- Forwardable
- Defined in:
- lib/websocketio/client.rb
Instance Attribute Summary collapse
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Class Method Summary collapse
-
.eof? ⇒ Boolean
TODO: FilterIO assume that eof? isn’t blocking method.
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(socket, handshake_args, options = {}) ⇒ Client
constructor
A new instance of Client.
- #write(str) ⇒ Object
Constructor Details
#initialize(socket, handshake_args, options = {}) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/websocketio/client.rb', line 14 def initialize(socket, handshake_args, = {}) @socket = socket @options = @handshake = WebSocket::Handshake::Client.new(handshake_args) @socket.write @handshake.to_s until @handshake.finished? do @handshake << @socket.getc end # TODO: FilterIO assume that eof? isn't blocking method. But TCPSocket#eof? is. # See http://docs.ruby-lang.org/en/2.2.0/IO.html#method-i-eof-3F def @socket.eof?; closed?; end @filtered_socket = filter(@socket, @handshake.version) end |
Instance Attribute Details
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
10 11 12 |
# File 'lib/websocketio/client.rb', line 10 def socket @socket end |
Class Method Details
.eof? ⇒ Boolean
TODO: FilterIO assume that eof? isn’t blocking method. But TCPSocket#eof? is. See docs.ruby-lang.org/en/2.2.0/IO.html#method-i-eof-3F
26 |
# File 'lib/websocketio/client.rb', line 26 def @socket.eof?; closed?; end |
Instance Method Details
#close ⇒ Object
30 31 32 33 34 35 |
# File 'lib/websocketio/client.rb', line 30 def close send_frame type: :close @socket.close @socket = nil @closed = true end |
#closed? ⇒ Boolean
37 38 39 |
# File 'lib/websocketio/client.rb', line 37 def closed? @closed end |
#write(str) ⇒ Object
41 42 43 44 |
# File 'lib/websocketio/client.rb', line 41 def write(str) send_frame data: str str.to_s.bytesize end |