diff --git a/python/grpcdemo_server.py b/python/grpcdemo_server.py new file mode 100644 index 0000000..8b4ee4d --- /dev/null +++ b/python/grpcdemo_server.py @@ -0,0 +1,31 @@ +from concurrent import futures + +import socket +import time + +import grpc +import grpcdemo_pb2 +import grpcdemo_pb2_grpc + +ONE_DAY = 60 * 60 * 24 # Sleep time in seconds +PORTNO = 6000 + +class HostDateTime(grpcdemo_pb2_grpc.HostDateTimeServicer): + + def SayHello(self, request, context): + return grpcdemo_pb2.CurrentDateTime(message='%s: %s!' % (socket.fqdn(), time.strftime("%c"))) + + +def serve(): + server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) + grpcdemo_pb2_grpc.add_HostDateTimeServicer_to_server(HostDateTime(), server) + server.add_insecure_port('[::]:%s' % PORTNO) + server.start() + try: + while True: + time.sleep(ONE_DAY) + except KeyboardInterrupt: + server.stop(0) + +if __name__ == '__main__': + serve()