Class: DRb::WebSocket::ServerSide
- Inherits:
-
Object
- Object
- DRb::WebSocket::ServerSide
- Defined in:
- lib/drb/websocket/server.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #close ⇒ Object
-
#initialize(ws, config, uri) ⇒ ServerSide
constructor
A new instance of ServerSide.
- #recv_request ⇒ Object
- #send_reply(succ, result) ⇒ Object
Constructor Details
#initialize(ws, config, uri) ⇒ ServerSide
Returns a new instance of ServerSide.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/drb/websocket/server.rb', line 82 def initialize(ws, config, uri) @uri = uri @config = config @msg = DRbMessage.new(@config) @ws = ws @messages = Messages.new @ws.on(:message) do |event| = event.data sender_id = .shift(36) EM.defer do res = @messages.(.pack('C*')) @ws.send(sender_id + res.bytes) end end end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
80 81 82 |
# File 'lib/drb/websocket/server.rb', line 80 def uri @uri end |
Instance Method Details
#alive? ⇒ Boolean
106 107 108 |
# File 'lib/drb/websocket/server.rb', line 106 def alive? !!@ws end |
#close ⇒ Object
99 100 101 102 103 104 |
# File 'lib/drb/websocket/server.rb', line 99 def close EM.defer do @ws.close @ws = nil end end |
#recv_request ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'lib/drb/websocket/server.rb', line 110 def recv_request begin @req_stream = StrStream.new(@messages.) @msg.recv_request(@req_stream) rescue close raise $! end end |
#send_reply(succ, result) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/drb/websocket/server.rb', line 120 def send_reply(succ, result) begin return unless alive? stream = StrStream.new @msg.send_reply(stream, succ, result) @messages.reply(stream.buf) rescue close raise $! end end |