示例#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.secure_server(
       methods.SERVER_METHODS, 0, resources.private_key(),
       resources.certificate_chain())
   self.server.start()
   port = self.server.port()
   self.stub = implementations.secure_stub(
       methods.CLIENT_METHODS, 'localhost', port,
       resources.test_root_certificates(), None, None,
       server_host_override=_SERVER_HOST_OVERRIDE)
示例#4
0
 def setUp(self):
     self.server = implementations.secure_server(
         methods.SERVICE_NAME, methods.SERVER_METHODS, 0,
         resources.private_key(), resources.certificate_chain())
     self.server.start()
     port = self.server.port()
     self.stub = implementations.secure_stub(
         methods.SERVICE_NAME,
         methods.CLIENT_METHODS,
         'localhost',
         port,
         resources.test_root_certificates(),
         None,
         None,
         server_host_override=_SERVER_HOST_OVERRIDE)