Class: WebSocketIO::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/websocketio/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @socket  = socket
  @options = 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

#socketObject (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

Returns:

  • (Boolean)


26
# File 'lib/websocketio/client.rb', line 26

def @socket.eof?; closed?; end

Instance Method Details

#closeObject



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

Returns:

  • (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