def run(): if len(sys.argv) >= 2: grpc_server = sys.argv[1] else: grpc_server = 'localhost:50051' channel = grpc.insecure_channel(grpc_server) stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message)
def run(): # 连接 rpc 服务器 channel = grpc.insecure_channel('localhost:50051') # 调用 rpc 服务 stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='czl')) print("Greeter client received: " + response.message) response = stub.SayHelloAgain(helloworld_pb2.HelloRequest(name='daydaygo')) print("Greeter client received: " + response.message)
def run(): interceptor = PromClientInterceptor() with grpc.insecure_channel('localhost:50051') as channel: intercept_channel = grpc.intercept_channel(channel, interceptor) stub = helloworld_pb2_grpc.GreeterStub(intercept_channel) response = stub.SayHello.future( helloworld_pb2.HelloRequest(name='you')) response = response.result() print("Greeter client received: " + response.message)
def run(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. # 为了避免暴露自己的IP地址 改成了127.0.0.1 with grpc.insecure_channel('127.0.0.1:50051') as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='ailx10')) print("Greeter client received: " + response.message)
def run(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. with grpc.insecure_channel(sys.argv[1]) as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message) response = stub.SayHelloAgain(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message)
def run(): channel = grpc.insecure_channel( str(container['NetworkSettings']['Networks']['bridge']['IPAddress']) + ':50051') stub = helloworld_pb2_grpc.GreeterStub(channel) for i in random.sample(range(30, 150), 10): response = stub.SayHello(helloworld_pb2.HelloRequest(name=str(i) + '')) print("Memory Pattern: " + response.message) time.sleep(1) time.sleep(1)
def create_greeter_stub(target='helloworld_server:50051'): """Creates a Greeter stub connecting to the given target Args: target: The host/port of the remote server Returns: A GreeterStub. """ return helloworld_pb2_grpc.GreeterStub(grpc.insecure_channel(target))
def run(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. with grpc.insecure_channel('localhost:50054') as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) #passing the input values for addition response = stub.SayHello(helloworld_pb2.HelloRequest(name=input("Enter the value of a:"), name2=input("Enter the value of b:"),)) print("Sum of a and b is: " + response.message)
def run(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. host = input("Enter your server's IP address: " ) # get the IP address of your Raspberry Pi with grpc.insecure_channel('{}:50051'.format(host)) as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message)
def run(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. #with grpc.insecure_channel('localhost:50051') as channel: global g_stub, g_channel g_channel = grpc.insecure_channel('localhost:50051') g_stub = helloworld_pb2_grpc.GreeterStub(g_channel) response = g_stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message)
def run(): channel = grpc.insecure_channel('localhost:50051') user_name=raw_input('What is your name? \n') stub = helloworld_pb2_grpc.GreeterStub(channel) # send server the user name and get the response from sayhello method response = stub.SayHello(helloworld_pb2.HelloRequest(name=user_name)) print("Greeter client received: " + response.message) # send server the user name and get the response from sayBye method response = stub.SayBye(helloworld_pb2.HelloRequest(name=user_name)) print("Greeter client received: " + response.message)
def run(): with grpc.insecure_channel("localhost:50051") as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name="Matthew")) print("Greeter client received: " + response.message) response = stub.SayHelloAgain( helloworld_pb2.HelloRequest(name="Matthew")) print("Greeter client received: " + response.message)
def run(): default_value = helloworld_pb2.HelloReply( message='Hello from your local interceptor!') default_value_interceptor = default_value_client_interceptor.DefaultValueClientInterceptor( default_value) channel = grpc.insecure_channel('localhost:50051') channel = grpc.intercept_channel(channel, default_value_interceptor) stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message)
def run(code): if len(textbox_1.get()) != 0: with grpc.insecure_channel('localhost:50051') as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name=code)) print(response.message) openNewWindow_1(response.message) else: openNewWindow_2()
def SayHello(self, request, context): with grpc.insecure_channel('server:80') as channel: #print("connect") stub = helloworld_pb2_grpc.GreeterStub(channel) #print("create stub") response = stub.SayHello(helloworld_pb2.HelloRequest(name='me')) #print("get res") print(response.message) return helloworld_pb2.HelloReply(message='Hello, %s! %s!' % (request.name, response.message))
def run(): #channel = grpc.insecure_channel('localhost:50051') channel = grpc.insecure_channel('{}:{}'.format(host, port)) stub = helloworld_pb2_grpc.GreeterStub(channel) try: response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message) except grpc.RpcError as err: print('Type:', type(err)) print('Attributes:', dir(err))
def run(grpcserver): channel = grpc.insecure_channel(grpcserver) stub = helloworld_pb2_grpc.GreeterStub(channel) while True: try: response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) logger.error("Greeter client received: " + response.message) time.sleep(3) except Exception as e: logger.error('Could not connect load-balancer. error {}'.format(e)) time.sleep(3)
def run(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. with grpc.insecure_channel('localhost:50051') as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.Request(name='from home')) print("Greeter client received: " + response.message) response = stub.SayBye(helloworld_pb2.Request(name='farewell')) print("Greeter client received: " + response.message)
def run(): channel = grpc.insecure_channel(os.environ['HOSTANDPORT']) stub = helloworld_pb2_grpc.GreeterStub(channel) while True: now = str(time.ctime()) response = stub.SayHello(helloworld_pb2.HelloRequest(name=now)) print("Greeter client received: " + response.message) response = stub.SayHelloAgain(helloworld_pb2.HelloRequest(name=now)) print("Greeter client received: " + response.message) time.sleep(2)
def run(id): with grpc.insecure_channel('localhost:50051') as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(id=id)) if response.message != "": output = f"{response.message} (ID: #{id})" else: output = f"Wait... I don't know you! (ID: #{id})" print(output)
def run(): header_adder_interceptor = header_manipulator_client_interceptor.header_adder_interceptor( 'one-time-password', '42') header_validator1 = header_manipulator_client_interceptor.header_adder_interceptor( 'one-time-password', '43') channel = grpc.insecure_channel('localhost:50051') channel = grpc.intercept_channel(channel, header_adder_interceptor, header_validator1) stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message)
def run(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. with grpc.insecure_channel('localhost:50051') as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) request = helloworld_pb2.HelloRequest(name="test") print("request: " + str(request)) response = stub.SayHello(request) print(response)
def run_secure_crt(): print('Secure Client call (crt)') private_crt_file = 'self.crt' trusted_certs = open(private_crt_file).read() credentials = grpc.ssl_channel_credentials(root_certificates=trusted_certs) channel = grpc.secure_channel('localhost:16506', credentials) stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received (crt): " + response.message)
def run(host, port): channel = grpc.insecure_channel('%s:%d' % (host, port)) stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.CallModel( helloworld_pb2.DoubleMatrix(rows=rows, cols=cols, channels=channels, data=image_content.flatten())) print("Greeter client received: " + response.message)
def run(server_address, secure): if secure: fallback_creds = grpc.experimental.insecure_channel_credentials() channel_creds = grpc.xds_channel_credentials(fallback_creds) channel = grpc.secure_channel(server_address, channel_creds) else: channel = grpc.insecure_channel(server_address) with channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message)
def main(): if len(sys.argv) > 1: name = sys.argv[1] else: name = 'you' with grpc.insecure_channel('localhost:50051') as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name=name)) print('Greeter client received: ' + response.message)
def run(): channel = grpc.insecure_channel('localhost:8765') stub = helloworld_pb2_grpc.GreeterStub(channel) print("connected to channel") response = stub.SayHello(helloworld_pb2.HelloRequest(name='Bala')) print("Greeter client received: " + str(response.id) + ' ' + response.name) response = stub.SayHelloAgain(helloworld_pb2.HelloRequest(name='Bkkk')) for item in response.data: print(item)
def run(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. with grpc.insecure_channel( 'grpc-server.default.svc.cluster.local:50051') as channel: for i in range(10): stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message) time.sleep(1)
def addPeer(self, peer): self.peersLocal.update({peer: 0}) channel = grpc.insecure_channel(self.registration.addrMe) stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SendPeer(helloworld_pb2.Peer(message=peer)) print(response.message)
def run(): with open('haproxy.crt', 'rb') as f: trusted_certs = f.read() credentials = grpc.ssl_channel_credentials(root_certificates=trusted_certs) #print(os.environ.get("SERVER_ADDRESS")) print("\n calling default server---- \n") channel = grpc.secure_channel(os.environ.get("SERVER_ADDRESS"), credentials) for _ in range(10): stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message)