Class: DatawireQuarkCore::WebsocketClient
- Inherits:
-
Object
- Object
- DatawireQuarkCore::WebsocketClient
- Extended by:
- Forwardable
- Defined in:
- lib/datawire-quark-core.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url) ⇒ WebsocketClient
constructor
A new instance of WebsocketClient.
- #issues ⇒ Object
- #run ⇒ Object
- #write(buffer) ⇒ Object
Constructor Details
#initialize(url) ⇒ WebsocketClient
Returns a new instance of WebsocketClient.
702 703 704 705 706 |
# File 'lib/datawire-quark-core.rb', line 702 def initialize(url) @url = url @client = ::WebSocket::Driver.client(self) @issues = WebscketIssues.new end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
707 708 709 |
# File 'lib/datawire-quark-core.rb', line 707 def url @url end |
Instance Method Details
#issues ⇒ Object
710 711 712 |
# File 'lib/datawire-quark-core.rb', line 710 def issues @issues end |
#run ⇒ Object
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/datawire-quark-core.rb', line 714 def run begin uri = URI(url) port = uri.port || (uri.scheme == "ws" ? 80 : 443) tcp = Celluloid::IO::TCPSocket.new(uri.host, port) if uri.scheme == "wss" @socket = Celluloid::IO::SSLSocket.new(tcp) @socket.connect else @socket = tcp end @client.start rescue ::Exception => err @issues.emit(:start_failed, err) else loop do begin @client.parse(@socket.readpartial(1024)) rescue EOFError break end end end end |
#write(buffer) ⇒ Object
742 743 744 |
# File 'lib/datawire-quark-core.rb', line 742 def write(buffer) @socket.write buffer end |