예제 #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()
예제 #5
0
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