Class: WebSocket::Connection
- Inherits:
-
Object
- Object
- WebSocket::Connection
- Defined in:
- lib/local_server.rb
Instance Attribute Summary collapse
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Class Method Summary collapse
Instance Method Summary collapse
- #each_message ⇒ Object
-
#initialize(socket, handshake) ⇒ Connection
constructor
A new instance of Connection.
- #puts(message) ⇒ Object
Constructor Details
#initialize(socket, handshake) ⇒ Connection
Returns a new instance of Connection.
22 23 24 25 |
# File 'lib/local_server.rb', line 22 def initialize(socket, handshake) @socket = socket @handshake = handshake end |
Instance Attribute Details
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
10 11 12 |
# File 'lib/local_server.rb', line 10 def socket @socket end |
Class Method Details
.establish(socket) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/local_server.rb', line 12 def self.establish(socket) handshake = WebSocket::Handshake::Server.new handshake << socket.gets until handshake.finished? raise "Malformed handshake received from WebSocket client" unless handshake.valid? socket.puts(handshake.to_s) Connection.new(socket, handshake) end |
Instance Method Details
#each_message ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/local_server.rb', line 32 def frame = WebSocket::Frame::Incoming::Server.new(version: @handshake.version) frame << @socket.read_nonblock(4096) while = frame.next yield end end |
#puts(message) ⇒ Object
27 28 29 30 |
# File 'lib/local_server.rb', line 27 def puts() frame = WebSocket::Frame::Outgoing::Server.new(version: @handshake.version, data: , type: :text) @socket.puts(frame.to_s) end |