echo_client.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  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 app that connects to a 'EchoWithoutProtobuf' service.
  16. #
  17. # Usage: $ path/to/echo_client.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. def main
  23. stub = EchoWithoutProtobuf::Stub.new('localhost:50051', :this_channel_is_insecure)
  24. user = ARGV.size > 0 ? ARGV[0] : 'world'
  25. message = stub.echo("hello #{user}")
  26. p "Response: #{message}"
  27. end
  28. main