def run_server(): with open(KEYFILE, 'rb') as f: private_key = f.read() with open(CERTFILE, 'rb') as f: certificate_chain = f.read() server_credentials = grpc.ssl_server_credentials( ((private_key, certificate_chain,),) ) # create a gRPC server server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) # use the generated function `add_CalculatorServicer_to_server` # to add the defined class to the server calculator_pb2_grpc.add_CalculatorServicer_to_server( CalculatorServicer(), server) # listen on port print('Starting server. Listening on port {}.'.format(LISTEN_PORT)) server.add_secure_port('[::]:{}'.format(LISTEN_PORT), server_credentials) 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)
def _serve(port: Text): bind_address = f"[::]:{port}" server = grpc.server(futures.ThreadPoolExecutor()) calculator_pb2_grpc.add_CalculatorServicer_to_server(Calculator(), server) server.add_insecure_port(bind_address) server.start() logging.info("Listening on %s.", bind_address) server.wait_for_termination()
def serve(): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) calculator_pb2_grpc.add_CalculatorServicer_to_server( CalculatorServicer(), server) print('Starting server. Listening on port 50051.') server.add_insecure_port('[::]:50051') server.start() server.wait_for_termination()
def serve(): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) calculator_pb2_grpc.add_CalculatorServicer_to_server(Calculator(), server) server.add_insecure_port('[::]:50051') server.start() try: while True: time.sleep(_ONE_DAY_IN_SECONDS) except KeyboardInterrupt: server.stop(0)
def serve(): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) calculator_pb2_grpc.add_CalculatorServicer_to_server( CalculatorMaster(), server) server.add_insecure_port(ADDRESS_SERVER_MASTER) server.start() print("Server Master started") try: while True: time.sleep(_ONE_DAY_IN_SECONDS) except KeyboardInterrupt: server.stop(0)
def main(): os.environ['GRPC_VERBOSITY'] = 'debug' a = "unused variable." class CalculatorServicer(calculator_pb2_grpc.CalculatorServicer): def SquareRoot(self, request, context): response = calculator_pb2.Number() response.value = calculator.square_root(request.value) return response def Multiply(self, request, context): response = calculator_pb2.Number() response.value = calculator.multiply(request.val1, request.val2) return response #server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) server = grpc.server(futures.ThreadPoolExecutor()) server_creds = grpc.alts_server_credentials() print(f'printing server credentials : {server_creds}') calculator_pb2_grpc.add_CalculatorServicer_to_server( CalculatorServicer(), server) print('Starting server. Listening on port 50051.') server.add_insecure_port('[::]:50051') #server.add_secure_port('localhost:50051', server_creds) server.start() b = False if b: print("hey this is a dead code block!!!") return 1 try: while True: time.sleep(86400) except KeyboardInterrupt: server.stop(0)
return response def __square_root(self, request, context): response = calculator_pb2.Number() response.value = calculator.square_root(request.value) return response # create a gRPC server #server = grpc.server(futures.ThreadPoolExecutor(max_workers=1)) loop = asyncio.get_event_loop() server = grpc.server(async_hack.AsyncioExecutor(loop=loop)) # use the generated function `add_CalculatorServicer_to_server` # to add the defined class to the created server calculator_pb2_grpc.add_CalculatorServicer_to_server( CalculatorServicer(loop), 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)
import grpc import calculator_pb2 import calculator_pb2_grpc import calculator from concurrent import futures import time class AddCalculatorServicer(calculator_pb2_grpc.CalculatorServicer): def AddNumber(self, request, context): output = calculator_pb2.OutputNumber() output.res_num = calculator.add_numbers(request.num_one, request.num_two) return output server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) calculator_pb2_grpc.add_CalculatorServicer_to_server(AddCalculatorServicer(), server) print('Server Active') server.add_insecure_port('[::]:50051') server.start() try: while True: time.sleep(80000) except KeyboardInterrupt: server.stop(0)
import grpc from concurrent import futures import time import threading import calculator_pb2 import calculator_pb2_grpc class Listener(calculator_pb2_grpc.CalculatorServicer): def sum(self, request, context): response = calculator_pb2.RNumber() response.value = request.value + request.value2 return response server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) calculator_pb2_grpc.add_CalculatorServicer_to_server(Listener(), server) print('Starting server. Listening on port 5001') server.add_insecure_port('[::]:5001') server.start() try: while True: time.sleep(86400) except KeyboardInterrupt: server.stop(0)
# calculator.square_root is exposed here # the request and response are of the data type # calculator_pb2.Number def SquareRoot(self, request, context): response = calculator_pb2.Number() response.value = calculator.square_root(request.value) return response # create a gRPC server server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) # use the generated function `add_CalculatorServicer_to_server` # to add the defined class to the server calculator_pb2_grpc.add_CalculatorServicer_to_server( CalculatorServicer(), 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)