Esempio n. 1
0
 def serve():
     server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
     echo_pb2_grpc.add_EchoServicer_to_server(Echoer(), server)
     server.add_insecure_port('[::]:50051')
     print("Start server")
     server.start()
     server.wait_for_termination()
Esempio n. 2
0
def serve():
    header_validator = RequestHeaderValidatorInterceptor(
        'one-time-password', '42', grpc.StatusCode.UNAUTHENTICATED,
        'Access denied!')
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10),
                         interceptors=(header_validator, ))
    echo_pb2_grpc.add_EchoServicer_to_server(EchoServicer(), server)
    server.add_insecure_port('[::]:50051')
    server.start()
    server.wait_for_termination()
Esempio n. 3
0
# create a class to define the server functions, derived from
class EchoServicer(echo_pb2_grpc.EchoServicer):

    # the request and response are of the data type
    # echo_pb2.Number
    def Response(self, request, context):
        response = echo_pb2.Set()
        response.value = echo.echo(request.value)
        response.number = echo.echo(request.number)
        return response


# create a gRPC server
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))

# to add the defined class to the server
echo_pb2_grpc.add_EchoServicer_to_server(EchoServicer(), server)

# listen on port 50051
print('Starting server. Listening on port 50051.')
server.add_insecure_port('[::]:50051')
server.start()

# since server.start() will not block,
# a sleep-loop is added to keep alive
try:
    while True:
        time.sleep(86400)
except KeyboardInterrupt:
    server.stop(0)
Esempio n. 4
0
    def __init__(self, port=5000):
        self.port = port

        self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
        echo_pb2_grpc.add_EchoServicer_to_server(ServerServiceExample(),
                                                 self.server)