echo_server.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env ruby
  2. # Copyright 2015 gRPC authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # Sample gRPC server that implements the EchoWithoutProtobuf service.
  16. #
  17. # Usage: $ path/to/echo_server.rb
  18. this_dir = File.expand_path(File.dirname(__FILE__))
  19. $LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir)
  20. require 'grpc'
  21. require 'echo_services_noprotobuf'
  22. # EchoServer is simple server that implements the EchoWithoutProtobuf server.
  23. class EchoServer < EchoWithoutProtobuf::Service
  24. # echo implements the EchoWithoutProtobuf 'Echo' rpc method.
  25. def echo(echo_req, _unused_call)
  26. echo_req
  27. end
  28. end
  29. # main starts an RpcServer that receives requests to EchoWithoutProtobuf at the sample
  30. # server port.
  31. def main
  32. s = GRPC::RpcServer.new
  33. s.add_http2_port('0.0.0.0:50051', :this_port_is_insecure)
  34. s.handle(EchoServer)
  35. s.run_till_terminated
  36. end
  37. main