예제 #1
0
파일: server.py 프로젝트: mindis/grpc
def serve():
  parser = argparse.ArgumentParser()
  parser.add_argument(
      '--port', help='the port on which to serve', type=int)
  parser.add_argument(
      '--use_tls', help='require a secure connection', dest='use_tls',
      action='store_true')
  args = parser.parse_args()

  if args.use_tls:
    private_key = resources.private_key()
    certificate_chain = resources.certificate_chain()
    server = implementations.secure_server(
        methods.SERVER_METHODS, args.port, private_key, certificate_chain)
  else:
    server = implementations.insecure_server(
        methods.SERVER_METHODS, args.port)

  server.start()
  logging.info('Server serving.')
  try:
    while True:
      time.sleep(_ONE_DAY_IN_SECONDS)
  except BaseException as e:
    logging.info('Caught exception "%s"; stopping server...', e)
    server.stop()
    logging.info('Server stopped; exiting.')
예제 #2
0
파일: server.py 프로젝트: zhangf911/grpc
def serve():
    parser = argparse.ArgumentParser()
    parser.add_argument('--port', help='the port on which to serve', type=int)
    parser.add_argument('--use_tls',
                        help='require a secure connection',
                        dest='use_tls',
                        action='store_true')
    args = parser.parse_args()

    if args.use_tls:
        private_key = resources.private_key()
        certificate_chain = resources.certificate_chain()
        server = implementations.secure_server(methods.SERVER_METHODS,
                                               args.port, private_key,
                                               certificate_chain)
    else:
        server = implementations.insecure_server(methods.SERVER_METHODS,
                                                 args.port)

    server.start()
    logging.info('Server serving.')
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except BaseException as e:
        logging.info('Caught exception "%s"; stopping server...', e)
        server.stop()
        logging.info('Server stopped; exiting.')
예제 #3
0
 def setUp(self):
     self.server = implementations.insecure_server(SERVICE_NAME,
                                                   _SERVICE_DESCRIPTIONS, 0)
     self.server.start()
     port = self.server.port()
     self.stub = implementations.insecure_stub(SERVICE_NAME,
                                               _INVOCATION_DESCRIPTIONS,
                                               'localhost', port)
예제 #4
0
 def setUp(self):
     self.server = implementations.insecure_server(methods.SERVICE_NAME,
                                                   methods.SERVER_METHODS,
                                                   0)
     self.server.start()
     port = self.server.port()
     self.stub = implementations.insecure_stub(methods.SERVICE_NAME,
                                               methods.CLIENT_METHODS,
                                               'localhost', port)
예제 #5
0
 def setUp(self):
   self.server = implementations.insecure_server(_SERVICE_DESCRIPTIONS, 0)
   self.server.start()
   port = self.server.port()
   self.stub = implementations.insecure_stub(_INVOCATION_DESCRIPTIONS, 'localhost', port)
예제 #6
0
 def setUp(self):
   self.server = implementations.insecure_server(methods.SERVER_METHODS, 0)
   self.server.start()
   port = self.server.port()
   self.stub = implementations.insecure_stub(
       methods.CLIENT_METHODS, 'localhost', port)