Class: PusherClient::WebSocket
- Inherits:
-
Object
- Object
- PusherClient::WebSocket
- Defined in:
- lib/pusher-client/websocket.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(url, params = {}) ⇒ WebSocket
constructor
A new instance of WebSocket.
- #receive ⇒ Object
- #send(data) ⇒ Object
- #socket ⇒ Object
Constructor Details
#initialize(url, params = {}) ⇒ WebSocket
Returns a new instance of WebSocket.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pusher-client/websocket.rb', line 8 def initialize(url, params = {}) @hs ||= LibWebSocket::OpeningHandshake::Client.new(:url => url, :version => params[:version]) @frame ||= LibWebSocket::Frame.new @socket = TCPSocket.new(@hs.url.host, @hs.url.port || 80) @socket.write(@hs.to_s) @socket.flush loop do data = @socket.getc next if data.nil? result = @hs.parse(data.chr) raise @hs.error unless result if @hs.done? @handshaked = true break end end end |
Instance Method Details
#close ⇒ Object
57 58 59 |
# File 'lib/pusher-client/websocket.rb', line 57 def close @socket.close end |
#receive ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pusher-client/websocket.rb', line 40 def receive raise "no handshake!" unless @handshaked data = @socket.gets("\xff") @frame.append(data) = [] while = @frame.next << end end |
#send(data) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/pusher-client/websocket.rb', line 32 def send(data) raise "no handshake!" unless @handshaked data = @frame.new(data).to_s @socket.write data @socket.flush end |
#socket ⇒ Object
53 54 55 |
# File 'lib/pusher-client/websocket.rb', line 53 def socket @socket end |