示例#1
0
文件: client.py 项目: singmiya/RPC
def main():
    chanel = grpc.insecure_channel('localhost:8080')
    # 使用Stub
    client = pi_pb2_grpc.PiCalculatorStub(chanel)
    # 调用
    for i in range(100000000000):
        client.Calc(pi_pb2.PiRequest(n=i))
示例#2
0
def main():
    channel = grpc.insecure_channel('localhost:8080', chan_ops)
    client = pi_pb2_grpc.PiCalculatorStub(channel)
    for i in range(10):
        try:
            res = client.Calc(pi_pb2.PiRequest(n=i))
            print "pi(%d) =" % i, res.value
        except grpc.RpcError as e:
            print e.code(), e.details()
示例#3
0
def main():
    channel = grpc.insecure_channel('localhost:8080')
    client = pi_pb2_grpc.PiCalculatorStub(channel)
    for i in range(0, 1000):
        try:
            print('pi(%d) =' % i,
                  client.Calc(pi_pb2.PiRequest(n=i), timeout=5).value)
        except grpc.RpcError as e:
            print(e.code())
            print(e.details())
示例#4
0
def main():
    # channel = grpc.insecure_channel('localhost:8080')

    chan_ops = [('grpc.default_compression_algorithm',
                 CompressionAlgorithm.gzip),
                ('grpc.grpc.default_compression_level', CompressionLevel.high)]
    channel = grpc.insecure_channel('localhost:8080', chan_ops)

    client = pi_pb2_grpc.PiCalculatorStub(channel)
    for i in range(2):
        try:
            print "pi(%d) =" % i, client.Calc(pi_pb2.PiRequest(n=i),
                                              timeout=5).value
        except grpc.RpcError as e:
            # print e.code(), e.details()
            print e.code(), e.initial_metadata()
def pi(client, k):
    return client.Calc(pi_pb2.PiRequest(n=k)).value
示例#6
0
def generate_request():
    for i in range(1, 100):
        yield pi_pb2.PiRequest(n=i)
示例#7
0
def main():
    channel = grpc.insecure_channel('localhost:8080')
    client = pi_pb2_grpc.PiCalculatorStub(channel)
    for i in range(1, 1000):
        print "pi(%d) = " % i, client.Calc(pi_pb2.PiRequest(n=i)).value