Class: Utopia::WebSocket::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/websocket/client.rb

Overview

This is a basic synchronous websocket client:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, socket) ⇒ Client

Returns a new instance of Client.



31
32
33
34
35
36
37
38
# File 'lib/utopia/websocket/client.rb', line 31

def initialize(url, socket)
	@url = url
	@socket = socket
	
	@driver = ::WebSocket::Driver.client(self)
	
	@driver.start
end

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver.



29
30
31
# File 'lib/utopia/websocket/client.rb', line 29

def driver
  @driver
end

#urlObject (readonly)

Returns the value of attribute url.



28
29
30
# File 'lib/utopia/websocket/client.rb', line 28

def url
  @url
end

Instance Method Details

#readObject



44
45
46
47
48
49
50
51
# File 'lib/utopia/websocket/client.rb', line 44

def read
	while true
		data = @socket.readpartial(1024)
		@driver.parse(data)
	end
rescue EOFError
	nil
end

#write(data) ⇒ Object



40
41
42
# File 'lib/utopia/websocket/client.rb', line 40

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