Class: Palapala::WebSocketClient

Inherits:
Object
  • Object
show all
Defined in:
lib/palapala/web_socket_client.rb

Overview

Create a socket wrapper that conforms to what the websocket-driver expects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ WebSocketClient

Returns a new instance of WebSocketClient.



11
12
13
14
15
# File 'lib/palapala/web_socket_client.rb', line 11

def initialize(url)
  @url = url
  uri = URI.parse(url)
  @socket = TCPSocket.new(uri.host, uri.port)
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/palapala/web_socket_client.rb', line 9

def url
  @url
end

Instance Method Details

#closeObject



25
26
27
# File 'lib/palapala/web_socket_client.rb', line 25

def close
  @socket.close
end

#readObject



21
22
23
# File 'lib/palapala/web_socket_client.rb', line 21

def read
  @socket.readpartial(1024)
end

#write(data) ⇒ Object



17
18
19
# File 'lib/palapala/web_socket_client.rb', line 17

def write(data)
  @socket.write(data)
end