main.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. *
  3. * Copyright 2018 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #import <Cocoa/Cocoa.h>
  19. #import <GRPCClient/GRPCCall+ChannelArg.h>
  20. #import <GRPCClient/GRPCCall+Tests.h>
  21. #import <GRPCClient/GRPCTransport.h>
  22. #if COCOAPODS
  23. #import <HelloWorld/Helloworld.pbrpc.h>
  24. #else
  25. #import "examples/protos/Helloworld.pbrpc.h"
  26. #endif
  27. static NSString * const kHostAddress = @"localhost:50051";
  28. @interface HLWResponseHandler : NSObject<GRPCProtoResponseHandler>
  29. @end
  30. // A response handler object dispatching messages to main queue
  31. @implementation HLWResponseHandler
  32. - (dispatch_queue_t)dispatchQueue {
  33. return dispatch_get_main_queue();
  34. }
  35. - (void)didReceiveProtoMessage:(GPBMessage *)message {
  36. NSLog(@"%@", message);
  37. }
  38. @end
  39. int main(int argc, const char * argv[]) {
  40. @autoreleasepool {
  41. HLWGreeter *client = [[HLWGreeter alloc] initWithHost:kHostAddress];
  42. HLWHelloRequest *request = [HLWHelloRequest message];
  43. request.name = @"Objective-C";
  44. GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
  45. // this example does not use TLS (secure channel); use insecure channel instead
  46. options.transport = GRPCDefaultTransportImplList.core_insecure;
  47. options.userAgentPrefix = @"HelloWorld/1.0";
  48. GRPCUnaryProtoCall *call = [client sayHelloWithMessage:request
  49. responseHandler:[[HLWResponseHandler alloc] init]
  50. callOptions:options];
  51. [call start];
  52. }
  53. return NSApplicationMain(argc, argv);
  54. }