Class: DRb::WebSocket::CallbackServer::ServerSide

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wsclient, sender_id, message, config, uri) ⇒ ServerSide

Returns a new instance of ServerSide.



40
41
42
43
44
45
46
47
# File 'lib/drb/websocket/callback_server.rb', line 40

def initialize(wsclient, sender_id, message, config, uri)
  @message = message
  @sender_id = sender_id
  @wsclient = wsclient
  @uri = uri
  @config = config
  @msg = DRbMessage.new(@config)
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



38
39
40
# File 'lib/drb/websocket/callback_server.rb', line 38

def uri
  @uri
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/drb/websocket/callback_server.rb', line 53

def alive?
  !!@wsclient
end

#closeObject



49
50
51
# File 'lib/drb/websocket/callback_server.rb', line 49

def close
  @wsclient = nil
end

#recv_requestObject



57
58
59
60
61
62
63
64
65
# File 'lib/drb/websocket/callback_server.rb', line 57

def recv_request
  begin
    @req_stream = StrStream.new(@message)
    @msg.recv_request(@req_stream)
  rescue
    close
    raise $!
  end
end

#send_reply(succ, result) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/drb/websocket/callback_server.rb', line 67

def send_reply(succ, result)
  begin
    return unless alive?
    stream = StrStream.new
    @msg.send_reply(stream, succ, result)
    @wsclient.send((@sender_id + stream.buf).bytes)
  rescue
    puts $!.full_message
    close
    raise $!
  end
end