当前位置: 首页>>代码示例>>Python>>正文


Python SimpleSSLWebSocketServer.serveforever方法代码示例

本文整理汇总了Python中SimpleWebSocketServer.SimpleSSLWebSocketServer.serveforever方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleSSLWebSocketServer.serveforever方法的具体用法?Python SimpleSSLWebSocketServer.serveforever怎么用?Python SimpleSSLWebSocketServer.serveforever使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleWebSocketServer.SimpleSSLWebSocketServer的用法示例。


在下文中一共展示了SimpleSSLWebSocketServer.serveforever方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start_server

# 需要导入模块: from SimpleWebSocketServer import SimpleSSLWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleSSLWebSocketServer import serveforever [as 别名]
def start_server():
   parser = OptionParser(usage="usage: %prog [options]", version="%prog 1.0")
   parser.add_option("--host", default='', type='string', action="store", dest="host", help="hostname (localhost)")
   parser.add_option("--port", default=9001, type='int', action="store", dest="port", help="port (9001)")
   parser.add_option("--example", default='echo', type='string', action="store", dest="example", help="echo, chat")
   parser.add_option("--ssl", default=0, type='int', action="store", dest="ssl", help="ssl (1: on, 0: off (default))")
   parser.add_option("--cert", default='./cert.pem', type='string', action="store", dest="cert", help="cert (./cert.pem)")
   parser.add_option("--ver", default=ssl.PROTOCOL_TLSv1, type=int, action="store", dest="ver", help="ssl version")

   (options, args) = parser.parse_args()

   os.system("rm ./unix_socket")
   cls = SimpleEcho
   if options.example == 'chat':
      cls = SimpleChat

   if options.ssl == 1:
      server = SimpleSSLWebSocketServer(options.host, options.port, cls, options.cert, options.cert, version=options.ver)
   else:
      server = SimpleWebSocketServer(options.host, options.port, cls)

   # def close_sig_handler(signal, frame):
   #    server.close()
   #    sys.exit()

   # serverThread = threading.Thread(target=other_thread)
   # serverThread.daemon = True
   # serverThread.start()

   #signal.signal(signal.SIGINT, close_sig_handler)

   server.serveforever()
开发者ID:muirt,项目名称:bbqbadass_server,代码行数:34,代码来源:SimpleExampleServer.py

示例2: WebSocketServer

# 需要导入模块: from SimpleWebSocketServer import SimpleSSLWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleSSLWebSocketServer import serveforever [as 别名]
class WebSocketServer(threading.Thread):
    def __init__(self, config, ns):
        threading.Thread.__init__(self)
        self.config = config
        self.net_server = ns
        self.daemon = True

    def run(self):
        t = WsClientThread(self.config, self.net_server)
        t.start()

        host = self.config.get("websocket_server")
        port = self.config.get("websocket_port", 9999)
        certfile = self.config.get("ssl_chain")
        keyfile = self.config.get("ssl_privkey")
        self.server = SimpleSSLWebSocketServer(host, port, ElectrumWebSocket, certfile, keyfile)
        self.server.serveforever()
开发者ID:CeeCeeCee,项目名称:electrum,代码行数:19,代码来源:websockets.py

示例3: WebSocketServer

# 需要导入模块: from SimpleWebSocketServer import SimpleSSLWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleSSLWebSocketServer import serveforever [as 别名]
class WebSocketServer(threading.Thread):

    def __init__(self, config: 'SimpleConfig', network: 'Network'):
        threading.Thread.__init__(self)
        self.config = config
        self.network = network
        asyncio.set_event_loop(network.asyncio_loop)
        self.daemon = True
        self.balance_monitor = BalanceMonitor(self.config, self.network)
        self.start()

    def run(self):
        asyncio.set_event_loop(self.network.asyncio_loop)
        host = self.config.get('websocket_server')
        port = self.config.get('websocket_port', 9999)
        certfile = self.config.get('ssl_chain')
        keyfile = self.config.get('ssl_privkey')
        self.server = SimpleSSLWebSocketServer(host, port, ElectrumWebSocket, certfile, keyfile)
        self.server.serveforever()
开发者ID:vialectrum,项目名称:vialectrum,代码行数:21,代码来源:websockets.py

示例4: OptionParser

# 需要导入模块: from SimpleWebSocketServer import SimpleSSLWebSocketServer [as 别名]
# 或者: from SimpleWebSocketServer.SimpleSSLWebSocketServer import serveforever [as 别名]
      

if __name__ == "__main__":

   parser = OptionParser(usage="usage: %prog [options]", version="%prog 1.0")
   parser.add_option("--host", default='', type='string', action="store", dest="host", help="hostname (localhost)")
   parser.add_option("--port", default=8000, type='int', action="store", dest="port", help="port (8000)")
   parser.add_option("--example", default='echo', type='string', action="store", dest="example", help="echo, chat")
   parser.add_option("--ssl", default=0, type='int', action="store", dest="ssl", help="ssl (1: on, 0: off (default))")
   parser.add_option("--cert", default='./cert.pem', type='string', action="store", dest="cert", help="cert (./cert.pem)")
   parser.add_option("--ver", default=ssl.PROTOCOL_TLSv1, type=int, action="store", dest="ver", help="ssl version")
   
   (options, args) = parser.parse_args()

   cls = SimpleEcho
   if options.example == 'chat':
      cls = SimpleChat	

   if options.ssl == 1:
      server = SimpleSSLWebSocketServer(options.host, options.port, cls, options.cert, options.cert, version=options.ver)
   else:	
      server = SimpleWebSocketServer(options.host, options.port, cls)

   def close_sig_handler(signal, frame):
      server.close()
      sys.exit()

   signal.signal(signal.SIGINT, close_sig_handler)

   server.serveforever()
开发者ID:AlexEdunov,项目名称:AvatarMotionServer,代码行数:32,代码来源:SimpleExampleServer.py


注:本文中的SimpleWebSocketServer.SimpleSSLWebSocketServer.serveforever方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。