Class: WEBSocket::Base::Socket
- Inherits:
-
Object
- Object
- WEBSocket::Base::Socket
- Defined in:
- lib/WEBSocket/socket.rb
Instance Method Summary collapse
- #<<(s) ⇒ Object
- #acquire_ownership(type) ⇒ Object
- #connect(host, port) ⇒ Object
- #evented? ⇒ Boolean
- #from_frame_to_text(str) ⇒ Object
- #from_text_to_frame(str) ⇒ Object
- #read(length = nil, buffer = nil) ⇒ Object
- #read_nonblock(length, buffer = nil) ⇒ Object
- #readpartial(length, buffer = nil) ⇒ Object
- #release_ownership(type) ⇒ Object
- #to_io ⇒ Object
- #wait_readable ⇒ Object
- #wait_writable ⇒ Object
- #write(s) ⇒ Object
- #write_nonblock(s) ⇒ Object
Instance Method Details
#<<(s) ⇒ Object
77 78 79 |
# File 'lib/WEBSocket/socket.rb', line 77 def << s @socket << from_text_to_frame(s.to_s) end |
#acquire_ownership(type) ⇒ Object
4 5 |
# File 'lib/WEBSocket/socket.rb', line 4 def acquire_ownership type end |
#connect(host, port) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/WEBSocket/socket.rb', line 7 def connect host, port @handshake = WebSocket::Handshake::Client.new :url => "ws://#{host}:#{port}" @socket.write @handshake.to_s msg = @socket.readpartial 4096 @handshake << msg @status = :connected end |
#evented? ⇒ Boolean
15 16 17 |
# File 'lib/WEBSocket/socket.rb', line 15 def evented? false end |
#from_frame_to_text(str) ⇒ Object
19 20 21 22 23 |
# File 'lib/WEBSocket/socket.rb', line 19 def from_frame_to_text str frame = WebSocket::Frame::Incoming::Client.new :version => @handshake.version frame << str frame.next.to_s end |
#from_text_to_frame(str) ⇒ Object
25 26 27 28 |
# File 'lib/WEBSocket/socket.rb', line 25 def from_text_to_frame str frame = WebSocket::Frame::Outgoing::Client.new :version => @handshake.version, :data => str, :type => :text frame.to_s end |
#read(length = nil, buffer = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/WEBSocket/socket.rb', line 30 def read length = nil, buffer = nil s = nil if length if length.kind_of? Numeric s = @socket.read length + 4, buffer elsif buffer.nil? s = @socket.read nil, length end else s = @socket.read nil, nil end from_frame_to_text s end |
#read_nonblock(length, buffer = nil) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/WEBSocket/socket.rb', line 44 def read_nonblock length, buffer = nil buffer ||= '' @socket.read_nonblock length + 4, buffer from_frame_to_text buffer end |
#readpartial(length, buffer = nil) ⇒ Object
51 52 53 54 |
# File 'lib/WEBSocket/socket.rb', line 51 def readpartial length, buffer = nil s = @socket.readpartial length + 4, buffer from_frame_to_text s end |
#release_ownership(type) ⇒ Object
56 57 |
# File 'lib/WEBSocket/socket.rb', line 56 def release_ownership type end |
#to_io ⇒ Object
59 60 61 |
# File 'lib/WEBSocket/socket.rb', line 59 def to_io @socket end |
#wait_readable ⇒ Object
63 64 |
# File 'lib/WEBSocket/socket.rb', line 63 def wait_readable end |
#wait_writable ⇒ Object
66 67 |
# File 'lib/WEBSocket/socket.rb', line 66 def wait_writable end |
#write(s) ⇒ Object
69 70 71 |
# File 'lib/WEBSocket/socket.rb', line 69 def write s @socket.write from_text_to_frame(s.to_s) end |
#write_nonblock(s) ⇒ Object
73 74 75 |
# File 'lib/WEBSocket/socket.rb', line 73 def write_nonblock s @socket.write_nonblock from_text_to_frame(s.to_s) end |