Class: Coronet::Support::RequestReplyServer
- Inherits:
-
GServer
- Object
- GServer
- Coronet::Support::RequestReplyServer
- Defined in:
- lib/coronet/support/request_reply_server.rb
Instance Method Summary collapse
- #handle(request) ⇒ Object
-
#initialize(port = 12345, format = MessageFormat::YamlMessageFormat.new, *args) ⇒ RequestReplyServer
constructor
A new instance of RequestReplyServer.
- #serve(io) ⇒ Object
Constructor Details
#initialize(port = 12345, format = MessageFormat::YamlMessageFormat.new, *args) ⇒ RequestReplyServer
Returns a new instance of RequestReplyServer.
5 6 7 8 9 10 |
# File 'lib/coronet/support/request_reply_server.rb', line 5 def initialize(port=12345, format=MessageFormat::YamlMessageFormat.new, *args) super(port, *args) @tcp = TransportMechanism::LengthPrefixedTcpTransport.new @format = format @count = 0 end |
Instance Method Details
#handle(request) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/coronet/support/request_reply_server.rb', line 20 def handle(request) @count += 1 # puts "--- mock host handling request #{@count}: #{request}" request['hello'] = 'client' if request.has_key? 'hello' request end |
#serve(io) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/coronet/support/request_reply_server.rb', line 12 def serve(io) packed_request = @tcp.read(io) request = @format.unpack(packed_request) response = handle(request) packed_response = @format.pack(response) @tcp.write(packed_response, io) end |