示例#1
0
 def ListNumbers(self, request, context):
     for i in range(10):
         sleep(0.1)
         response = calculator_pb2.Number()
         response.value = i
         yield response
     for i in range(20):
         sleep(0.2)
         response = calculator_pb2.Number()
         response.value = i * 100
         yield response
示例#2
0
 async def SquareRoot(self, request, context):
     #task = asyncio.ensure_future(__square_root(request, context))
     #response = self.__square_root(request, context)
     print(request)
     response = calculator_pb2.Number()
     response.value = await calculator.square_root(request.value)
     return response
示例#3
0
def run():
    with grpc.insecure_channel('localhost:50051') as channel:
        stub = calculator_pb2_grpc.CalculatorStub(channel)

        number = calculator_pb2.Number(value=81)
        response = stub.SquareRoot(number)
        print(response.value)
示例#4
0
 def SquareEight(self, request, context):
     print("Executando SquareEight")
     response = calculator_pb2.Number()
     response.value = calculator.sq_eight(request.x1, request.x2,
                                          request.x3, request.x4,
                                          request.x5, request.x6,
                                          request.x7, request.x8)
     return response
示例#5
0
def get_call(loop, number):
    # open a gRPC channel
    channel = grpc.insecure_channel('localhost:50051')
    # create a stub (client)
    stub = calculator_pb2_grpc.CalculatorStub(channel)
    number = calculator_pb2.Number(value=number)
    response = stub.SquareRoot(number)
    print(response)
    return response
def run():
    with grpc.insecure_channel('localhost:50051') as channel:
        stub = calculator_pb2_grpc.CalculatorStub(channel)
        number = calculator_pb2.Number(value1=99, value2=88)
        response = stub.Add(number)
    print(
        str(response.value1) + ' + ' + str(response.value2) + " = " +
        str(response.result))
    while True:
        time.sleep(_ONE_DAY_IN_SECONDS)
示例#7
0
    def squareRoot(self, number):
        # create a valid request message
        number = calculator_pb2.Number(value=number)

        # make the call
        response = self.stub.SquareRoot(number)

        # et voilà
        # print(response.value)

        return response.value
示例#8
0
def square_root(val: float):

    # open a gRPC channel
    channel = grpc.insecure_channel('localhost:50051')

    # create a stub (client)
    stub = calculator_pb2_grpc.CalculatorStub(channel)

    # create a valid request message
    number = calculator_pb2.Number(value=val)

    # make the call
    response = stub.SquareRoot(number)

    # et voilà
    print(response.value)
示例#9
0
 def SquareRoot(self, request, context):
     record = {
         "nombre": request.nombre,
         "departamento": request.departamento,
         "edad": request.edad,
         "Forma de contagio": request.formaDeContagio,
         "estado": request.estado
     }
     redisRecord = {
         "nombre": request.nombre,
         "departamento": request.departamento,
         "edad": request.edad,
         "Forma de contagio": request.formaDeContagio,
         "estado": request.estado
     }
     try:
         x = mycol.insert_one(record)
         print(x.inserted_id)
         r.lpush('casoscovid', json.dumps(redisRecord, sort_keys=True))
     except Exception as err:
         print(err)
     response = calculator_pb2.Number()
     response.nombre = request.nombre
     return response
示例#10
0
import grpc

# import the generated classes
import calculator_pb2
import calculator_pb2_grpc

# open a gRPC channel
channel = grpc.insecure_channel('localhost:50051')

# create a stub (client)
stub = calculator_pb2_grpc.CalculatorStub(channel)

input_num = int(input("Enter the Number : "))
# create a valid request message
number = calculator_pb2.Number(value=input_num)

# make the call
response = stub.SquareRoot(number)

# et voilà
print(response.value)
示例#11
0
文件: client.py 项目: Rajeshrash/grpc
# import the generated classes
import calculator_pb2
import calculator_pb2_grpc

# open a gRPC channel
channel = grpc.insecure_channel('localhost:50051')

# create a stub (client)
stub = calculator_pb2_grpc.CalculatorStub(channel)

stub1 = calculator_pb2_grpc.CalculatorNewStub(channel)

stub2 = calculator_pb2_grpc.Welcome_MessageStub(channel)

number = calculator_pb2.Number(value=25)

new_number = calculator_pb2.Number(value=36)

message = calculator_pb2.Welcome(hello="Rajesh")

response = stub1.SquareRoot(new_number)

print(response.value)

response = stub.SquareRoot(number)

print(response.value)

response = stub2.WelcomeMessage(message)
示例#12
0
 def SquareRoot(self, request, context):
     response = calculator_pb2.Number()
     response.value = calculator.get_extension(request.value)
     return response
示例#13
0
import grpc

# import the generated classes
import calculator_pb2
import calculator_pb2_grpc

# open a gRPC channel
channel = grpc.insecure_channel('localhost:50051')

# create a stub (client)
stub = calculator_pb2_grpc.CalculatorStub(channel)

# create a valid request message
temp = calculator_pb2.Number(value=16, test=3)

response = stub.SquareRoot(temp)
print(response.value, response.val)
示例#14
0
 def SquareRoot(self, request, context):
     print("Recieved Request with input: ", request.value)
     response = calculator_pb2.Number()
     response.value = calculator.square_root(request.value)
     return response
示例#15
0
 def SquareRoot(self, request, context):
     response = calculator_pb2.Number()
     print("Server response prepared with type: ", type(response), response)
     response.value = calculator.square_root(request.value)
     return response
示例#16
0
import grpc

# import the generated classes
import calculator_pb2
import calculator_pb2_grpc

# open a gRPC channel
channel = grpc.insecure_channel('localhost:50051')

# create a stub (client)
stub = calculator_pb2_grpc.CalculatorStub(channel)

# create a valid request message
number = calculator_pb2.Number(nombre="dennis.catro",
                               departamento="Guatemala",
                               edad=28,
                               formaDeContagio="Comunitario",
                               estado="recuperado")

# make the call
response = stub.SquareRoot(number)

# et voilà
print(response.nombre)
示例#17
0
 def Addition(self, request, context):
     response = calculator_pb2.Number()
     response.value = calculator.addition(request.value_one,
                                          request.value_two)
     return response
示例#18
0
 def Substrc(self, request, context):
     response = calculator_pb2.Number()
     response.value = calculator.subing(request.valueA, request.valueB)
     return response
 def SquareRoot(self, request, context):
     response = calculator_pb2.Number()
     response.value = calculator.square_root(request.value)
     return response
示例#20
0
 def MatMult(self, request, context):
     response = calculator_pb2.Number()
     response.msg = calculator.matrix_multiplication(
         request.value1, request.value2, request.value3, request.value4)
     return response
示例#21
0
import grpc

# import the generated classes
import calculator_pb2
import calculator_pb2_grpc

# open a gRPC channel
channel = grpc.insecure_channel('localhost:50051')

# create a stub (client)
stub = calculator_pb2_grpc.CalculatorStub(channel)

# create a valid request message

# expression = 'x+y+c'
# expression_and_value = {'x': 1, 'y': 2, 'c': 3}

expression = 111.123
number = calculator_pb2.Number(value=expression)

# make the call
response = stub.SquareRoot(number)

# et voilà
print(response.value)
示例#22
0
 def Factorial(self, request, context):
     print('Factorial Called')
     response = calculator_pb2.Number()
     response.value = calculator.factorial(request.value)
     return response
示例#23
0
 def SquareRoot(self, request, context):
     print('GRPC Server SquareRoot called with:', request.value)
     response = calculator_pb2.Number()
     response.value = calculator.square_root(request.value)
     return response
示例#24
0
def create_iterator():
    while (True):
        inp = int(input())
        number = calculator_pb2.Number(value=inp)
        yield number
示例#25
0
 def Add(self, request, context):
     response = calculator_pb2.Number()
     response.value = calculator.add(request.values)
     print(response.value)
     return response
示例#26
0
 def SquareRoot(self, request, context):
     print("Executando Square")
     response = calculator_pb2.Number()
     response.value = calculator.square_root(request.value)
     return response
示例#27
0
# import the generated classes
import calculator_pb2
import calculator_pb2_grpc

# open a gRPC channel
channel = grpc.insecure_channel('localhost:50051')

# create a stub (client)
stub = calculator_pb2_grpc.CalculatorStub(channel)

# create a valid request message
msg = calculator_pb2.Message(msg="Alan")

# create a valid request message
number = calculator_pb2.Number(value=16)

# make the call
response = stub.HelloWorld(msg)

print(response.msg)

response = stub.SquareRoot(number)

print(response.value)


number2 = calculator_pb2.Number2(x=16, y=4)

# make the call
response = stub.Sum(number2)
示例#28
0
 def SendSubstract(self, request, context):
     response = calculator_pb2.Number()
     response.value = calculator.sendSubstract(request.value)
     return response
 def Multiply(self, request, context):
     response = calculator_pb2.Number()
     response.value = calculator.multiply(request.val1, request.val2)
     return response
示例#30
0
# open a gRPC channel
channel = grpc.insecure_channel('localhost:50051')

# create a stub (client)
stub = calculator_pb2_grpc.CalculatorStub(channel)

# define the rows and columns
row1 = 7
col1 = 8
row2 = 8
col2 = 2

start = time.clock()

# create a valid request message
number = calculator_pb2.Number(value1=row1,
                               value2=col1,
                               value3=row2,
                               value4=col2)

# make the call
response = stub.MatMult(number)

print("Matriz resultante: ")
print('Ordem: {one}x{two}'.format(one=row1, two=col2))

# you make it
print(response.msg)

print time.clock() - start