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.



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

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.



7
8
9
# File 'lib/palapala/web_socket_client.rb', line 7

def url
  @url
end

Instance Method Details

#closeObject



23
24
25
# File 'lib/palapala/web_socket_client.rb', line 23

def close
  @socket.close
end

#readObject



19
20
21
# File 'lib/palapala/web_socket_client.rb', line 19

def read
  @socket.readpartial(1024)
end

#write(data) ⇒ Object



15
16
17
# File 'lib/palapala/web_socket_client.rb', line 15

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