Class: Utopia::WebSocket::Client
- Inherits:
-
Object
- Object
- Utopia::WebSocket::Client
- Defined in:
- lib/utopia/websocket/client.rb
Overview
This is a basic synchronous websocket client:
Instance Attribute Summary collapse
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url, socket) ⇒ Client
constructor
A new instance of Client.
- #read ⇒ Object
- #write(data) ⇒ Object
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
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
29 30 31 |
# File 'lib/utopia/websocket/client.rb', line 29 def driver @driver end |
#url ⇒ Object (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
#read ⇒ Object
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 |