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


Python WebSocketServerFactory.setProtocolOptions方法代码示例

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


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

示例1: startService

# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import setProtocolOptions [as 别名]
    def startService(self):

        factory = WebSocketServerFactory("ws://localhost:%d" % self.port, debug=self.debug)

        factory.protocol = EchoServerProtocol
        factory.setProtocolOptions(allowHixie76=True)  # needed if Hixie76 is to be supported

        # FIXME: Site.start/stopFactory should start/stop factories wrapped as Resources
        factory.startFactory()

        resource = WebSocketResource(factory)

        # we server static files under "/" ..
        webdir = os.path.abspath(pkg_resources.resource_filename("echows", "web"))
        root = File(webdir)

        # and our WebSocket server under "/ws"
        root.putChild("ws", resource)

        # both under one Twisted Web Site
        site = Site(root)
        site.protocol = HTTPChannelHixie76Aware  # needed if Hixie76 is to be supported

        self.site = site
        self.factory = factory

        self.listener = reactor.listenTCP(self.port, site)
开发者ID:Avnerus,项目名称:AutobahnPython,代码行数:29,代码来源:echoservice.py

示例2: getAutoBahn

# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import setProtocolOptions [as 别名]
def getAutoBahn(core, port=80):
   #from twisted.python import log as tlog
   #tlog.startLogging(sys.stdout)

   wsuri = "ws://localhost"
   if not port in ['80','443']:
      wsuri+=":"+str(port)
   #factory = WebSocketServerFactory(wsuri, debug=True, debugCodePaths=True)
   factory = WebSocketServerFactory(wsuri)
   factory.core = core
   factory.protocol = AutobahnProtocolWrapper
   factory.setProtocolOptions(allowHixie76 = True)
   resource = WebSocketResource(factory)
   log.debug("AutoBahn started")
   return resource
开发者ID:,项目名称:,代码行数:17,代码来源:

示例3: _setUpListener

# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import setProtocolOptions [as 别名]
 def _setUpListener(self, serviceName, port, protocol, handler=None):
     url = "ws://localhost:%d"%(port)       
     factory = WebSocketServerFactory(url, debug=True, debugCodePaths=True)    
     factory.protocol = protocol
     factory.setProtocolOptions(allowHixie76=True)
     
     #HACK: add an array for observing messages
     factory.observers = [] #called for every message; for the ui to listen
     
     if handler !=None:
         factory.observers.append(handler)
     
     factory.connections = [] #all connections that are active; for the protocol to send data
     self.frontEndListeners[serviceName] = factory
     listenWS(self.frontEndListeners[serviceName]) 
     
开发者ID:kudox,项目名称:ctf_scorebot5,代码行数:17,代码来源:StaticFlagSocket.py

示例4: EchoServerProtocol

# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import setProtocolOptions [as 别名]
                               listenWS


class EchoServerProtocol(WebSocketServerProtocol):

   def onMessage(self, msg, binary):
      self.sendMessage(msg, binary)


if __name__ == '__main__':

   if len(sys.argv) > 1 and sys.argv[1] == 'debug':
      log.startLogging(sys.stdout)
      debug = True
   else:
      debug = False

   factory = WebSocketServerFactory("ws://localhost:9000",
                                    debug = debug,
                                    debugCodePaths = debug)

   factory.protocol = EchoServerProtocol
   factory.setProtocolOptions(allowHixie76 = True)
   listenWS(factory)

   webdir = File(".")
   web = Site(webdir)
   reactor.listenTCP(8080, web)

   reactor.run()
开发者ID:Aerobota,项目名称:autobahn_rce,代码行数:32,代码来源:server.py

示例5: WebSocketTestServerProtocol

# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import setProtocolOptions [as 别名]
from twisted.internet import reactor, ssl
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol, listenWS


class WebSocketTestServerProtocol(WebSocketServerProtocol):

   def onMessage(self, msg, binary):
      self.sendMessage(msg, binary)


if __name__ == '__main__':

   log.startLogging(sys.stdout)

   ## SSL server context: load server key and certificate
   ##
   contextFactory = ssl.DefaultOpenSSLContextFactory('keys/server.key', 'keys/server.crt')

   ## create a WS server factory with our protocol
   ##
   factory = WebSocketServerFactory("wss://localhost:9000", debug = False)
   factory.setProtocolOptions(failByDrop = False)
   factory.protocol = WebSocketTestServerProtocol

   ## Listen for incoming WebSocket connections: wss://localhost:9000
   ##
   listenWS(factory, contextFactory)

   log.msg("Using Twisted reactor class %s" % str(reactor.__class__))
   reactor.run()
开发者ID:hansent,项目名称:Autobahn,代码行数:32,代码来源:test_autobahn_wss.py

示例6: onMessage

# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import setProtocolOptions [as 别名]
   def onMessage(self, msg, isBinary):
      if self.service:
         self.service.onMessage(msg, isBinary)

   def onClose(self, wasClean, code, reason):
      if self.service:
         self.service.onClose(wasClean, code, reason)


if __name__ == '__main__':

   if len(sys.argv) > 1 and sys.argv[1] == 'debug':
      log.startLogging(sys.stdout)
      debug = True
   else:
      debug = False

   factory = WebSocketServerFactory("ws://localhost:9000",
                                    debug = debug,
                                    debugCodePaths = debug)

   factory.protocol = ServiceServerProtocol
   factory.setProtocolOptions(allowHixie76 = True, failByDrop = False)
   listenWS(factory)

   webdir = File(".")
   web = Site(webdir)
   reactor.listenTCP(8080, web)

   reactor.run()
开发者ID:Aerobota,项目名称:autobahn_rce,代码行数:32,代码来源:server1.py

示例7: len

# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import setProtocolOptions [as 别名]
      for data in payload:
         l += len(data)
         self.sha256.update(data)
      digest = self.sha256.hexdigest()
      print "Received frame with payload length %7d, compute digest: %s" % (l, digest)
      self.sendMessage(digest)

   def onMessageEnd(self):
      self.sha256 = None


if __name__ == '__main__':

   factory = WebSocketServerFactory("ws://localhost:9000")
   factory.protocol = FrameBasedHashServerProtocol

   enableCompression = True
   if enableCompression:
      from autobahn.compress import PerMessageDeflateOffer, \
                                    PerMessageDeflateOfferAccept
      ## Function to accept offers from the client ..
      def accept(offers):
         for offer in offers:         
            if isinstance(offer, PerMessageDeflateOffer):
               return PerMessageDeflateOfferAccept(offer)

      factory.setProtocolOptions(perMessageCompressionAccept = accept)

   listenWS(factory)
   reactor.run()
开发者ID:CatBakun,项目名称:AutobahnPython,代码行数:32,代码来源:frame_based_server.py

示例8: static_from_root

# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import setProtocolOptions [as 别名]
      db.session.add(user)
      db.session.commit()
   except IntegrityError:
      return "IntegrityError"
   except:return "ServerError"
   return "true"
@app.route('/scriptcam.lic')
def static_from_root():
   return redirect('/static/ScriptCam/scriptcam.lic')

##
## create a Twisted Web resource for our WebSocket server
##
msgFactory = WebSocketServerFactory(IP,debug = debug,debugCodePaths = debug)
msgFactory.protocol = MsgServerProtocol
msgFactory.setProtocolOptions(allowHixie76 = True) # needed if Hixie76 is to be supported
msgResource = WebSocketResource(msgFactory)

imgFactory = WebSocketServerFactory(IP,debug = debug,debugCodePaths = debug)
imgFactory.protocol = ImgServerProtocol
imgFactory.setProtocolOptions(allowHixie76 = True) # needed if Hixie76 is to be supported
imgResource = WebSocketResource(imgFactory)

##
## create a Twisted Web WSGI resource for our Flask server
##
wsgiResource = WSGIResource(reactor, reactor.getThreadPool(), app)

##
## create a root resource serving everything via WSGI/Flask, but
## the path "/ws" served by our WebSocket stuff
开发者ID:grantges,项目名称:titanium-websocket,代码行数:33,代码来源:run.py

示例9: websocket_func

# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import setProtocolOptions [as 别名]
def websocket_func(logger, host, port):
    cons = list()

    # noinspection PyUnusedLocal
    def sigint_handler(signum, frame):
        reactor.stop()

    signal.signal(signal.SIGINT, sigint_handler)

    def send_to_all(msg, except_connection=None):
        if except_connection:
            logger.debug("Sending to all except %d message: %s", id(except_connection), msg)
        else:
            logger.debug("Sending to all: %s", msg)
        json_msg = json.dumps(msg)
        for con in cons:
            if con == except_connection:
                continue
            logger.debug("Sending to %d message: %s", id(con), msg)
            con.sendMessage(json_msg, False)

    class EchoServerProtocol(WebSocketServerProtocol):

        def __init__(self):
            pass

        def send_error(self, error_message):
            logger.error(error_message)
            self.send_to_self({"type": "error", "response": error_message})

        def send_to_self(self, msg):
            logger.debug("Sending to self: %s", msg)
            json_msg = json.dumps(msg)
            self.sendMessage(json_msg, False)

        def send_to_others(self, msg):
            send_to_all(msg, self)

        def onMessage(self, msg, binary):
            if binary:
                return
            try:
                data = json.loads(msg)
                data_type = str(data["type"])
                if "ping" == data_type:
                    self.on_message_ping(data)
                elif "register" == data_type:
                    self.on_message_register(data)
                elif "data" == data_type:
                    self.on_message_data(data)
                else:
                    self.send_error("Received unknown message type: %s" % data_type)
            except Exception as e:
                self.send_error("Error: %s, in message: %s" % (str(e), msg))

        def on_message_data(self, data):
            self.send_to_self({
                "type": "data",
                "id": data["id"],
                "message": base64.b64encode(data["message"])
            })
            self.send_to_others({
                "type": "chat",
                "from": str(id(self)),
                "message": data["message"]
            })

        def on_message_register(self, data):
            auth_token = data["auth_token"]
            if auth_token in VALID_AUTH_TOKENS:
                cons.append(self)
                self.send_to_self({"type": "registered", "response": "you are cool"})
            else:
                self.send_error("Wrong auth token")

        def on_message_ping(self, data):
            self.send_to_self({"type": "pong", "message": data["message"]})

        def onClose(self, was_clean, code, reason):
            logger.debug("Disconnected: %s" % id(self))
            if self in cons:
                cons.remove(self)

        def onOpen(self):
            logger.debug("Connected: %s" % id(self))

    url = "ws://%s:%d" % (host, port)

    factory = WebSocketServerFactory(url)
    factory.protocol = EchoServerProtocol
    factory.setProtocolOptions(allowHixie76=True)

    resource = WebSocketResource(factory)

    root = Resource()
    root.putChild("ws", resource)

    site = Site(root)
    site.protocol = HTTPChannelHixie76Aware

#.........这里部分代码省略.........
开发者ID:Librari,项目名称:JavaWebsocketClient,代码行数:103,代码来源:websocket.py

示例10: start_server

# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import setProtocolOptions [as 别名]
def start_server():
    factory = WebSocketServerFactory("ws://127.0.0.1:9000")
    factory.protocol = EchoServerProtocol
    factory.setProtocolOptions(allowHixie76 = True)
    listenWS(factory)
开发者ID:edwardgeorge,项目名称:wsaccel,代码行数:7,代码来源:bench.py


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