コード例 #1
0
ファイル: client.py プロジェクト: zhwindy/py-gRPC
def run_client():
    channel = grpc.insecure_channel(ADDRESS)
    client = data_pb2_grpc.FormatDataStub(channel)

    for _ in range(10):
        response = client.doFormat(data_pb2.Data(test="hello world"))
        print("Result:", response.test)
コード例 #2
0
def run(dir_path,_HOST ,_PORT = '21328'):

    # with grpc.insecure_channel('localhost:50051') as channel:
    #     stub = helloworld_pb2_grpc.GreeterStub(channel)
    #     response1 = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))

    # conn = grpc.insecure_channel(_HOST + ':' + _PORT)  # 监听频道
    # print(conn)
    # client = data_pb2_grpc.FormatDataStub(channel=conn)   # 客户端使用Stub类发送请求,参数为频道,为了绑定链接
    # print(client)

    with grpc.insecure_channel(_HOST + ':' + _PORT) as channel:
        stub = data_pb2_grpc.FormatDataStub(channel)
        for (root, dirs, files) in os.walk(dir_path, False):
            for filename in files:
                if not filename.endswith(".jpg") and not filename.endswith(".bmp"):
                    continue
                file_path = os.path.join(root, filename)
                with open(file_path, "rb") as f:
                    file_bytes = base64.b64encode(f.read())
                    # print("len(file_bytes)=", len(file_bytes),type(file_bytes))
                    # print(file_bytes)
                response = stub.DoFormat(data_pb2.actionrequest(data=file_bytes))  # 返回的结果就是proto中定义的类
                print(filename)
                print("received result: " + response.text)
コード例 #3
0
ファイル: rpc_client.py プロジェクト: secoba/apimonitor
def run():
    conn = grpc.insecure_channel(_HOST + ':' + _PORT)  # 监听频道
    client = data_pb2_grpc.FormatDataStub(
        channel=conn)  # 客户端使用Stub类发送请求,参数为频道,为了绑定链接
    response = client.DoFormat(
        data_pb2.actionrequest(text='hello,world!',
                               corpus="NEWS"))  # 返回的结果就是proto中定义的类
    for i in response.result:
        print(i)
コード例 #4
0
def run(country, city, map_info=None):
    if map_info:
        text = country + '&' + city + '&' + map_info
    else:
        text = country + '&' + city
    conn = grpc.insecure_channel(_HOST + ':' + _PORT)
    client = data_pb2_grpc.FormatDataStub(channel=conn)
    response = client.DoFormat(data_pb2.Data(text=text))
    print("received: " + response.text)
コード例 #5
0
ファイル: client-main.py プロジェクト: hzt63631407/python
def run():
    conn = grpc.insecure_channel(_HOST + ':' + _PORT)  # 监听频道
    print(conn)
    client = data_pb2_grpc.FormatDataStub(
        channel=conn)  # 客户端使用Stub类发送请求,参数为频道,为了绑定链接
    print(client)
    response = client.DoFormat(
        data_pb2.actionrequest(text='hello,world!'))  # 返回的结果就是proto中定义的类
    print("received: " + response.text)
コード例 #6
0
def run(country,city,map_info=None,province=None):
    if not province:
        #print ('asd')
        if map_info:
            text = country + '&' + city + '&' + map_info
        else:
            text = country + '&' + city
    else:
        if map_info:
            text = country + '&' + city + '&' + map_info + '~' + province
            #print (text)
        else:
            text = country + '&' + city + '~' + province
            #print('a',text)
    conn = grpc.insecure_channel(_HOST + ':' + _PORT)
    client = data_pb2_grpc.FormatDataStub(channel=conn)
    response = client.DoFormat(data_pb2.Data(text=text))
    print("received: " + response.text)
    return response.text
コード例 #7
0
ファイル: client.py プロジェクト: stoensin/deep-imitation
def run():
    conn = grpc.insecure_channel(_HOST + ':' + _PORT)
    client = data_pb2_grpc.FormatDataStub(channel=conn)
    response = client.DoFormat(data_pb2.Data(text='hello,world!'))
    print("received: " + response.text)
コード例 #8
0
 def get_craw(self):
     conn = grpc.insecure_channel('192.168.1.100' + ':' + '2333')
     client = data_pb2_grpc.FormatDataStub(channel=conn)
     response = client.DoFormat(data_pb2.Data(text='getData'))
     craw_file = json.loads(response.text)
     return craw_file
コード例 #9
0
def run():
	conn = grpc.insecure_channel(_HOST + ':' + _PORT)
	client = data_pb2_grpc.FormatDataStub(channel = conn)
	print('Send: ' + _TEXT)
	response = client.DoFormat(data_pb2.Data(text = _TEXT))
	print('Received: ' + response.text)