當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。