def run(): with grpc.insecure_channel('localhost:50051') as channel: greeter_stub = helloworld_pb2_grpc.GreeterStub(channel) route_guide_stub = route_guide_pb2_grpc.RouteGuideStub(channel) greeter_response = greeter_stub.SayHello( helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + greeter_response.message) print("-------------- GetFeature --------------") route_guide_client.guide_get_feature(route_guide_stub) print("-------------- ListFeatures --------------") route_guide_client.guide_list_features(route_guide_stub) print("-------------- RecordRoute --------------") route_guide_client.guide_record_route(route_guide_stub) print("-------------- RouteChat --------------") route_guide_client.guide_route_chat(route_guide_stub)
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( target='grpc-server-balancer.default.svc.cluster.local:8000', options=[('grpc.lb_policy_name', 'grpclb'), ('grpc.enable_retries', 0), ('grpc.dns_enable_srv_queries', 1), ('grpc.keepalive_timeout_ms', 10000)]) as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) for x in range(10000): response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter (Python): " + response.message, flush=True) time.sleep(1)
def get_post_javascript_data(): """ Objetivo: Essa funcao realiza as seguintes operacoes: 1- Recebe a mensagem do client por meio de do metodo POST 2- Chama a rotina do servidor para processar a mensagem recebida 3- Recebe do servidor uma resposta 4- Retorna resposta recebida do servidor para o frontend """ # instanciando canal de comunicacao grpc with grpc.insecure_channel('localhost:50051') as channel: # recebe a mensagem do client por ajax msg = request.form['msg_cliente'] # obtem a resposta do chatbot chamando o servidor e retorna para o frontend stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name=msg)) return str(response.message)
def run(): with grpc.insecure_channel('localhost:50051') as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) name = 'replay' if len(sys.argv) == 2: if sys.argv[1] == 'rec': name = 'record' elif sys.argv[1] == 'rep': name = 'replay' else: exit(-1) response = stub.SayHello(helloworld_pb2.HelloRequest(name=name)) print("Greeter client received: " + response.message)
def runSecured(): with open('server.crt', 'rb') as f: trusted_certs = f.read() credentials = grpc.ssl_channel_credentials( open('server.crt', 'rb').read() ) #grpc.ssl_channel_credentials(root_certificates=trusted_certs) channel = grpc.secure_channel('{}:{}'.format(host, port), credentials) stub = helloworld_pb2_grpc.GreeterStub(channel) try: response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("secured client received: " + response.message) except grpc.RpcError as err: print('Type:', type(err)) print('Attributes:', dir(err))
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. # # For more channel options, please see https://grpc.io/grpc/core/group__grpc__arg__keys.html with grpc.insecure_channel( target='localhost:50051', options=[('grpc.lb_policy_name', 'pick_first'), ('grpc.enable_retries', 0), ('grpc.keepalive_timeout_ms', 10000)]) as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) # Timeout in seconds. # Please refer gRPC Python documents for more detail. https://grpc.io/grpc/python/grpc.html response = stub.SayHello( helloworld_pb2.HelloRequest(name='you'), timeout=10) 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. host = 'localhost' port = '50051' opts, args = getopt.getopt(sys.argv[1:], "h:p:", ["host=", "port="]) for opt, arg in opts: if opt in ("-h", "--host"): host = arg elif opt in ("-p", "--port"): port = arg with grpc.insecure_channel(host + ':' + port) as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='Larry')) print("Greeter client received: " + response.message)
def run(): host = 'localhost' port = 50051 if len(sys.argv) > 1: port = int(sys.argv[1]) channel = grpc.insecure_channel('%s:%d' % (host, port)) stub = helloworld_pb2_grpc.GreeterStub(channel) name = 'python client' print("Will try to greet the server as " + name) response = stub.SayHello(helloworld_pb2.HelloRequest(name=name), #add a 9k header metadata=( ('x-big-header', 'X'*(1024*9)), ) ) print("Got this response from the server: " + 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('192.168.56.7:9080') as channel: a = datetime.datetime.now() N = 10000 for i in range(N): stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello.with_call( helloworld_pb2.HelloRequest(), metadata= (('authorization', 'LDAP SHViZXJ0IEouIEZhcm5zd29ydGgsb3U9cGVvcGxlOnByb2Zlc3Nvcg==' ), )) b = datetime.datetime.now() print("Perf is:", ((b - a).total_seconds() / N) * 1000, " ms per call") """ response = stub.SayHelloAgain(helloworld_pb2.HelloRequest(name='you'))
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: greeter_stub = helloworld_pb2_grpc.GreeterStub(channel) route_guide_stub = route_guide_pb2_grpc.RouteGuideStub(channel) greeter_response = greeter_stub.SayHello( helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + greeter_response.message) print("-------------- GetFeature --------------") guide_get_feature(route_guide_stub) print("-------------- ListFeatures --------------") guide_list_features(route_guide_stub) print("-------------- RecordRoute --------------") guide_record_route(route_guide_stub) print("-------------- RouteChat --------------") guide_route_chat(route_guide_stub)
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 channel1, grpc.insecure_channel( 'localhost:50052') as channe2: stub = helloworld_pb2_grpc.GreeterStub(channel1) request = helloworld_pb2.HelloRequest(name='you') response = stub.SayHello(request) print("Greeter client received: " + response.message) response = stub.SayHelloAgain(request) print("Greeter client received: " + response.message) stub = helloworld_pb2_grpc.KillerStub(channe2) request = helloworld_pb2.KillRequest(who_to_kill='you') response = stub.Kill(request) print("Greeter client received: " + str(response.kill_reply))
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, call = stub.SayHello.with_call( helloworld_pb2.HelloRequest(name='you'), metadata=( ('initial-metadata-1', 'The value should be str'), ('binary-metadata-bin', b'With -bin surffix, the value can be bytes'), ('accesstoken', 'gRPC Python is great'), )) print("Greeter client received: " + response.message) for key, value in call.trailing_metadata(): print('Greeter client received trailing metadata: key=%s value=%s' % (key, value))
def do_request(msg): response = stub.SayHello(helloworld_pb2.HelloRequest(name=msg)) return response.message
def run(): channel = grpc.insecure_channel('localhost:50051') #canal local que se abre del servidor al cliente grpc stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) return "Nuevo cliente recibido" + response.message
def test_hw_ola(): """ Test GreeterServicer Ola method """ response = stub.Ola(helloworld_pb2.HelloRequest(name="John")) print("Greeter client received: " + response.message)
# See the License for the specific language governing permissions and # limitations under the License. """The Python implementation of the GRPC helloworld.Greeter client.""" from __future__ import print_function from concurrent import futures import grpc import helloworld_pb2 import helloworld_pb2_grpc 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: <<<<<<< HEAD ======= #with grpc.insecure_channel('dliforsup:50051') as channel: >>>>>>> 1d851238f26d64796720a9370a202a20ae3aeb0a with grpc.insecure_channel('9.181.92.123:50051') as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message) if __name__ == '__main__': run()
async def fetch(loop, id, name): async with aiohttp.ClientSession(loop=loop, json_serialize=ujson.dumps) as session: data = helloworld_pb2.HelloRequest(name=name) data = data.SerializeToString() r = await session.post('http://130.193.48.105:8080', data=data) d = await r.read()
def handler(event, context): with grpc.insecure_channel(endpoint) as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello( helloworld_pb2.HelloRequest(name=event['name'])) print("Received from backend: " + 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) sair = True data = "" while bool(sair): opcao = int( input(''' \n\n# MENU PRINCIPAL #\n 1 - Criar contato 2 - Procurar contato 3 - Atualizar contato 4 - Remover contato 0 - Sair - > ''')) print("Sua escolha foi:", opcao) if opcao == 1: nome = '' endereco = '' email = '' telefones = '' print("\nNOVO CONTATO\n") nome = raw_input('Digite o nome do novo contato: ') endereco = raw_input('Digite o endereco do novo contato: ') email = raw_input('Digite o email do novo contato: ') while True: aux_telefones = raw_input( 'Digite o telefone (ou deixe em branco para sair): ') if len(aux_telefones) == 0: break if len(telefones) == 0: telefones = aux_telefones else: telefones = telefones + "+" + aux_telefones contato = "1_" + nome + "_" + endereco + "_" + email + "_" + telefones #print("Mensagem que sera mandada para o server: " + contato) response = '' response = stub.AdicionarContato( helloworld_pb2.HelloRequest(name=contato)) print("\nMensagem recebida do servidor:", response.message) pass elif opcao == 2: print("\nPROCURAR CONTATO\n") nome = '' nome = raw_input('Digite o nome a ser procurado: ') contato = "2_" + nome response = stub.ProcurarContato( helloworld_pb2.HelloRequest(name=contato)) print("\nMensagem recebida do servidor:", response.message) pass elif opcao == 3: #Update contact print("\nATUALIZAR CONTATO\n") nome = '' nome = raw_input('Digite o nome a ser atualizado: ') contato = "3_" + nome response = stub.AtualizarContato( helloworld_pb2.HelloRequest(name=contato)) print('\nMensagem recebida do servidor:' + response.message) if response.message == 'Nao encontrei nenhum contato': print('') else: contato2 = '' print("\nDADOS NOVOS DO CONTATO\n") nome = '' endereco = '' email = '' telefones = '' nome = raw_input('Digite o nome do novo contato: ') endereco = raw_input('Digite o endereco do novo contato: ') email = raw_input('Digite o email do novo contato: ') while True: aux_telefones = raw_input( 'Digite o telefone (ou deixe em branco para sair): ' ) if len(aux_telefones) == 0: break if len(telefones) == 0: telefones = aux_telefones else: telefones = telefones + "+" + aux_telefones contato2 = "5_" + nome + "_" + endereco + "_" + email + "_" + telefones #print("Msg que sera mandada para o server: " + contato2) response2 = stub.AtualizarDadosContato( helloworld_pb2.HelloRequest(name=contato2)) print('\nMensagem recebida do servidor: ' + response2.message) pass elif opcao == 4: #DELETE print("\nDELETAR CONTATO\n") nome = '' nome = raw_input('Digite o nome a ser removido: ') contato = "4_" + nome response = stub.DeletarContato( helloworld_pb2.HelloRequest(name=contato)) print('\nMensagem recebida do servidor: ' + response.message) pass elif opcao == 0: print("Encerrou a conexao com o server!") sair = False
import grpc import helloworld_pb2 import helloworld_pb2_grpc host = '127.0.0.1' PORT = 30051 if __name__ == "__main__": channel = grpc.insecure_channel(host + ':' + str(PORT)) client = helloworld_pb2_grpc.GreeterStub(channel) resp = client.SayHello(helloworld_pb2.HelloRequest(name='Hunt')) print(resp)
def request(port, message): channel = grpc.insecure_channel('localhost:' + str(port)) stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name=message)) print("Received: " + response.message)
def run(host, port): channel = grpc.insecure_channel('%s:%d' % (host, port)) stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='cool guy')) print("Greeter client received: " + response.message)
def run(self): self.stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
def run(): with grpc.insecure_channel('localhost:8888') as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='Ishan')) print(response.message)
def run(port, name): with grpc.insecure_channel('localhost: %s' % port) as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name=name)) print(response.message)
def run(): channel = implementations.insecure_channel('localhost', 50051) stub = helloworld_pb2.beta_create_Greeter_stub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'), _TIMEOUT_SECONDS) print("Greeter client received: " + response.message)
def main(): channel = grpc.insecure_channel("127.0.0.1:50051") stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name="zhangsan")) print(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='SHAHRIAR')) print("Greeter Client Received: "+ response.message )
def run(): channel = grpc.insecure_channel('localhost:50051') stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) 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='you')) return f"Greeter client received: {response.message} \n"