Class: DRb::WebSocket::ServerSide

Inherits:
Object
  • Object
show all
Defined in:
lib/drb/websocket/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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|
    message = event.data
    sender_id = message.shift(36)
    EM.defer do
      res = @messages.recv_message(message.pack('C*'))
      @ws.send(sender_id + res.bytes)
    end
  end
end

Instance Attribute Details

#uriObject (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

Returns:

  • (Boolean)


106
107
108
# File 'lib/drb/websocket/server.rb', line 106

def alive?
  !!@ws
end

#closeObject



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_requestObject



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.request_message)
    @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