remove debugCodePaths
This commit is contained in:
@@ -529,7 +529,6 @@ class WebSocketProtocol(object):
|
||||
"""Status codes allowed to send in close."""
|
||||
|
||||
CONFIG_ATTRS_COMMON = ['debug',
|
||||
'debugCodePaths',
|
||||
'logOctets',
|
||||
'logFrames',
|
||||
'trackTimings',
|
||||
@@ -664,15 +663,13 @@ class WebSocketProtocol(object):
|
||||
"""
|
||||
Implements :func:`autobahn.websocket.interfaces.IWebSocketChannel.onMessage`
|
||||
"""
|
||||
if self.debug:
|
||||
self.log.debug("WebSocketProtocol.onMessage")
|
||||
self.log.debug("WebSocketProtocol.onMessage(payload=<{payload_len} bytes)>, isBinary={isBinary}", payload_len=(len(payload) if payload else 0), isBinary=isBinary)
|
||||
|
||||
def onPing(self, payload):
|
||||
"""
|
||||
Implements :func:`autobahn.websocket.interfaces.IWebSocketChannel.onPing`
|
||||
"""
|
||||
if self.debug:
|
||||
self.log.debug("WebSocketProtocol.onPing")
|
||||
self.log.debug("WebSocketProtocol.onPing(payload=<{payload_len} bytes>)", payload_len=(len(payload) if payload else 0))
|
||||
if self.state == WebSocketProtocol.STATE_OPEN:
|
||||
self.sendPong(payload)
|
||||
|
||||
@@ -680,28 +677,13 @@ class WebSocketProtocol(object):
|
||||
"""
|
||||
Implements :func:`autobahn.websocket.interfaces.IWebSocketChannel.onPong`
|
||||
"""
|
||||
if self.debug:
|
||||
self.log.debug("WebSocketProtocol.onPong")
|
||||
self.log.debug("WebSocketProtocol.onPong(payload=<{payload_len} bytes>)", payload_len=(len(payload) if payload else 0))
|
||||
|
||||
def onClose(self, wasClean, code, reason):
|
||||
"""
|
||||
Implements :func:`autobahn.websocket.interfaces.IWebSocketChannel.onClose`
|
||||
"""
|
||||
if self.debugCodePaths:
|
||||
s = "WebSocketProtocol.onClose:\n"
|
||||
s += "wasClean=%s\n" % wasClean
|
||||
s += "code=%s\n" % code
|
||||
s += "reason=%s\n" % reason
|
||||
s += "self.closedByMe=%s\n" % self.closedByMe
|
||||
s += "self.failedByMe=%s\n" % self.failedByMe
|
||||
s += "self.droppedByMe=%s\n" % self.droppedByMe
|
||||
s += "self.wasClean=%s\n" % self.wasClean
|
||||
s += "self.wasNotCleanReason=%s\n" % self.wasNotCleanReason
|
||||
s += "self.localCloseCode=%s\n" % self.localCloseCode
|
||||
s += "self.localCloseReason=%s\n" % self.localCloseReason
|
||||
s += "self.remoteCloseCode=%s\n" % self.remoteCloseCode
|
||||
s += "self.remoteCloseReason=%s\n" % self.remoteCloseReason
|
||||
self.log.debug(s)
|
||||
self.log.debug("WebSocketProtocol.onClose(wasClean={wasClean}, code={code}, reason={reason})", wasClean=wasClean, code=code, reason=reason)
|
||||
|
||||
def onCloseFrame(self, code, reasonRaw):
|
||||
"""
|
||||
@@ -711,13 +693,10 @@ class WebSocketProtocol(object):
|
||||
(when we are a client and expect the server to drop the TCP).
|
||||
|
||||
:param code: Close status code, if there was one (:class:`WebSocketProtocol`.CLOSE_STATUS_CODE_*).
|
||||
:type code: int or None
|
||||
:type code: int
|
||||
:param reasonRaw: Close reason (when present, a status code MUST have been also be present).
|
||||
:type reason: str or None
|
||||
:type reasonRaw: bytes
|
||||
"""
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("WebSocketProtocol.onCloseFrame")
|
||||
|
||||
self.remoteCloseCode = code
|
||||
|
||||
# reserved close codes: 0-999, 1004, 1005, 1006, 1011-2999, >= 5000
|
||||
@@ -749,8 +728,7 @@ class WebSocketProtocol(object):
|
||||
# cancel any closing HS timer if present
|
||||
#
|
||||
if self.closeHandshakeTimeoutCall is not None:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("closeHandshakeTimeoutCall.cancel")
|
||||
self.log.debug("connection closed properly: canceling closing handshake timeout")
|
||||
self.closeHandshakeTimeoutCall.cancel()
|
||||
self.closeHandshakeTimeoutCall = None
|
||||
|
||||
@@ -809,15 +787,14 @@ class WebSocketProtocol(object):
|
||||
"""
|
||||
self.serverConnectionDropTimeoutCall = None
|
||||
if self.state != WebSocketProtocol.STATE_CLOSED:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("onServerConnectionDropTimeout")
|
||||
self.log.debug("timeout: server did not drop TCP connection (in time)")
|
||||
self.wasClean = False
|
||||
self.wasNotCleanReason = u'server did not drop TCP connection (in time)'
|
||||
self.wasServerConnectionDropTimeout = True
|
||||
self.dropConnection(abort=True)
|
||||
else:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("skipping onServerConnectionDropTimeout since connection is already closed")
|
||||
# ok, connection is already closed!
|
||||
pass
|
||||
|
||||
def onOpenHandshakeTimeout(self):
|
||||
"""
|
||||
@@ -827,21 +804,19 @@ class WebSocketProtocol(object):
|
||||
"""
|
||||
self.openHandshakeTimeoutCall = None
|
||||
if self.state in [WebSocketProtocol.STATE_CONNECTING, WebSocketProtocol.STATE_PROXY_CONNECTING]:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("onOpenHandshakeTimeout fired")
|
||||
self.log.debug("opening handshake timeout: peer did not finish (in time) the opening handshake")
|
||||
self.wasClean = False
|
||||
self.wasNotCleanReason = u'peer did not finish (in time) the opening handshake'
|
||||
self.wasOpenHandshakeTimeout = True
|
||||
self.dropConnection(abort=True)
|
||||
elif self.state == WebSocketProtocol.STATE_OPEN:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("skipping onOpenHandshakeTimeout since WebSocket connection is open (opening handshake already finished)")
|
||||
self.log.debug("skipping opening handshake timeout: WebSocket connection is open (opening handshake already finished)")
|
||||
|
||||
elif self.state == WebSocketProtocol.STATE_CLOSING:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("skipping onOpenHandshakeTimeout since WebSocket connection is closing")
|
||||
self.log.debug("skipping opening handshake timeout: WebSocket connection is already closing ..")
|
||||
|
||||
elif self.state == WebSocketProtocol.STATE_CLOSED:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("skipping onOpenHandshakeTimeout since WebSocket connection already closed")
|
||||
self.log.debug("skipping opening handshake timeout: WebSocket connection is already closed")
|
||||
else:
|
||||
# should not arrive here
|
||||
raise Exception("logic error")
|
||||
@@ -854,23 +829,20 @@ class WebSocketProtocol(object):
|
||||
"""
|
||||
self.closeHandshakeTimeoutCall = None
|
||||
if self.state != WebSocketProtocol.STATE_CLOSED:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("onCloseHandshakeTimeout fired")
|
||||
self.log.debug("closing handshake timeout: peer did not finish (in time) the closing handshake")
|
||||
self.wasClean = False
|
||||
self.wasNotCleanReason = u'peer did not respond (in time) in closing handshake'
|
||||
self.wasCloseHandshakeTimeout = True
|
||||
self.dropConnection(abort=True)
|
||||
else:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("skipping onCloseHandshakeTimeout since connection is already closed")
|
||||
self.log.debug("skipping closing handshake timeout: WebSocket connection is already closed")
|
||||
|
||||
def onAutoPingTimeout(self):
|
||||
"""
|
||||
When doing automatic ping/pongs to detect broken connection, the peer
|
||||
did not reply in time to our ping. We drop the connection.
|
||||
"""
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("Auto ping/pong: onAutoPingTimeout fired")
|
||||
self.log.debug("Auto ping/pong: onAutoPingTimeout fired")
|
||||
|
||||
self.autoPingTimeoutCall = None
|
||||
self.dropConnection(abort=True)
|
||||
@@ -891,8 +863,7 @@ class WebSocketProtocol(object):
|
||||
|
||||
self._closeConnection(abort)
|
||||
else:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("skipping dropConnection since connection is already closed")
|
||||
self.log.debug("skipping dropConnection since connection is already closed")
|
||||
|
||||
def _fail_connection(self, code=CLOSE_STATUS_CODE_GOING_AWAY, reason=u'going away'):
|
||||
"""
|
||||
@@ -919,8 +890,7 @@ class WebSocketProtocol(object):
|
||||
self.dropConnection(abort=False)
|
||||
|
||||
else:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("skipping failConnection since connection is already closed")
|
||||
self.log.debug("skipping failConnection since connection is already closed")
|
||||
|
||||
def _protocol_violation(self, reason):
|
||||
"""
|
||||
@@ -931,9 +901,10 @@ class WebSocketProtocol(object):
|
||||
|
||||
:returns: bool -- True, when any further processing should be discontinued.
|
||||
"""
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("Protocol violation: {reason}", reason=reason)
|
||||
self.log.debug("Protocol violation: {reason}", reason=reason)
|
||||
|
||||
self._fail_connection(WebSocketProtocol.CLOSE_STATUS_CODE_PROTOCOL_ERROR, reason)
|
||||
|
||||
if self.failByDrop:
|
||||
return True
|
||||
else:
|
||||
@@ -952,9 +923,10 @@ class WebSocketProtocol(object):
|
||||
|
||||
:returns: bool -- True, when any further processing should be discontinued.
|
||||
"""
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("Invalid payload: {reason}", reason=reason)
|
||||
self.log.debug("Invalid payload: {reason}", reason=reason)
|
||||
|
||||
self._fail_connection(WebSocketProtocol.CLOSE_STATUS_CODE_INVALID_PAYLOAD, reason)
|
||||
|
||||
if self.failByDrop:
|
||||
return True
|
||||
else:
|
||||
@@ -1099,23 +1071,21 @@ class WebSocketProtocol(object):
|
||||
# cancel any server connection drop timer if present
|
||||
#
|
||||
self.log.debug('_connectionLost: {reason}', reason=reason)
|
||||
|
||||
if not self.factory.isServer and self.serverConnectionDropTimeoutCall is not None:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("serverConnectionDropTimeoutCall.cancel")
|
||||
self.log.debug("serverConnectionDropTimeoutCall.cancel")
|
||||
self.serverConnectionDropTimeoutCall.cancel()
|
||||
self.serverConnectionDropTimeoutCall = None
|
||||
|
||||
# cleanup auto ping/pong timers
|
||||
#
|
||||
if self.autoPingPendingCall:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("Auto ping/pong: canceling autoPingPendingCall upon lost connection")
|
||||
self.log.debug("Auto ping/pong: canceling autoPingPendingCall upon lost connection")
|
||||
self.autoPingPendingCall.cancel()
|
||||
self.autoPingPendingCall = None
|
||||
|
||||
if self.autoPingTimeoutCall:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("Auto ping/pong: canceling autoPingTimeoutCall upon lost connection")
|
||||
self.log.debug("Auto ping/pong: canceling autoPingTimeoutCall upon lost connection")
|
||||
self.autoPingTimeoutCall.cancel()
|
||||
self.autoPingTimeoutCall = None
|
||||
|
||||
@@ -1234,8 +1204,7 @@ class WebSocketProtocol(object):
|
||||
|
||||
# ignore any data received after WS was closed
|
||||
#
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("received data in STATE_CLOSED")
|
||||
self.log.debug("received data in STATE_CLOSED")
|
||||
|
||||
# should not arrive here (invalid state)
|
||||
#
|
||||
@@ -1283,8 +1252,8 @@ class WebSocketProtocol(object):
|
||||
if self.logOctets:
|
||||
self.logTxOctets(e[0], e[1])
|
||||
else:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("skipped delayed write, since connection is closed")
|
||||
self.log.debug("skipped delayed write, since connection is closed")
|
||||
|
||||
# we need to reenter the reactor to make the latter
|
||||
# reenter the OS network stack, so that octets
|
||||
# can get on the wire. Note: this is a "heuristic",
|
||||
@@ -1735,8 +1704,7 @@ class WebSocketProtocol(object):
|
||||
if self.autoPingPending:
|
||||
try:
|
||||
if payload == self.autoPingPending:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("Auto ping/pong: received pending pong for auto-ping/pong")
|
||||
self.log.debug("Auto ping/pong: received pending pong for auto-ping/pong")
|
||||
|
||||
if self.autoPingTimeoutCall:
|
||||
self.autoPingTimeoutCall.cancel()
|
||||
@@ -1747,11 +1715,9 @@ class WebSocketProtocol(object):
|
||||
if self.autoPingInterval:
|
||||
self.autoPingPendingCall = txaio.call_later(self.autoPingInterval, self._sendAutoPing)
|
||||
else:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("Auto ping/pong: received non-pending pong")
|
||||
except:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("Auto ping/pong: received non-pending pong")
|
||||
except:
|
||||
self.log.debug("Auto ping/pong: received non-pending pong")
|
||||
|
||||
# fire app-level callback
|
||||
#
|
||||
@@ -1873,8 +1839,7 @@ class WebSocketProtocol(object):
|
||||
|
||||
def _sendAutoPing(self):
|
||||
# Sends an automatic ping and sets up a timeout.
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("Auto ping/pong: sending ping auto-ping/pong")
|
||||
self.log.debug("Auto ping/pong: sending ping auto-ping/pong")
|
||||
|
||||
self.autoPingPendingCall = None
|
||||
|
||||
@@ -1883,8 +1848,7 @@ class WebSocketProtocol(object):
|
||||
self.sendPing(self.autoPingPending)
|
||||
|
||||
if self.autoPingTimeout:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("Auto ping/pong: expecting ping in {0} seconds for auto-ping/pong".format(self.autoPingTimeout))
|
||||
self.log.debug("Auto ping/pong: expecting ping in {0} seconds for auto-ping/pong".format(self.autoPingTimeout))
|
||||
self.autoPingTimeoutCall = txaio.call_later(self.autoPingTimeout, self.onAutoPingTimeout)
|
||||
|
||||
def sendPong(self, payload=None):
|
||||
@@ -1908,12 +1872,10 @@ class WebSocketProtocol(object):
|
||||
frame with invalid payload.
|
||||
"""
|
||||
if self.state == WebSocketProtocol.STATE_CLOSING:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("ignoring sendCloseFrame since connection is closing")
|
||||
self.log.debug("ignoring sendCloseFrame since connection is closing")
|
||||
|
||||
elif self.state == WebSocketProtocol.STATE_CLOSED:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("ignoring sendCloseFrame since connection already closed")
|
||||
self.log.debug("ignoring sendCloseFrame since connection already closed")
|
||||
|
||||
elif self.state in [WebSocketProtocol.STATE_PROXY_CONNECTING, WebSocketProtocol.STATE_CONNECTING]:
|
||||
raise Exception("cannot close a connection not yet connected")
|
||||
@@ -2528,8 +2490,7 @@ class WebSocketServerProtocol(WebSocketProtocol):
|
||||
if port != self.factory.externalPort:
|
||||
return self.failHandshake("port %d in HTTP Host header '%s' does not match server listening port %s" % (port, str(self.http_request_host), self.factory.externalPort))
|
||||
else:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("skipping opening handshake port checking - neither WS URL nor external port set")
|
||||
self.log.debug("skipping opening handshake port checking - neither WS URL nor external port set")
|
||||
|
||||
self.http_request_host = h
|
||||
|
||||
@@ -2539,8 +2500,7 @@ class WebSocketServerProtocol(WebSocketProtocol):
|
||||
if not ((self.factory.isSecure and self.factory.externalPort == 443) or (not self.factory.isSecure and self.factory.externalPort == 80)):
|
||||
return self.failHandshake("missing port in HTTP Host header '%s' and server runs on non-standard port %d (wss = %s)" % (str(self.http_request_host), self.factory.externalPort, self.factory.isSecure))
|
||||
else:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("skipping opening handshake port checking - neither WS URL nor external port set")
|
||||
self.log.debug("skipping opening handshake port checking - neither WS URL nor external port set")
|
||||
|
||||
# Upgrade
|
||||
#
|
||||
@@ -2567,16 +2527,13 @@ class WebSocketServerProtocol(WebSocketProtocol):
|
||||
url = self.http_request_params['redirect'][0]
|
||||
if 'after' in self.http_request_params and len(self.http_request_params['after']) > 0:
|
||||
after = int(self.http_request_params['after'][0])
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("HTTP Upgrade header missing : render server status page and meta-refresh-redirecting to %s after %d seconds" % (url, after))
|
||||
self.log.debug("HTTP Upgrade header missing : render server status page and meta-refresh-redirecting to %s after %d seconds" % (url, after))
|
||||
self.sendServerStatus(url, after)
|
||||
else:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("HTTP Upgrade header missing : 303-redirecting to %s" % url)
|
||||
self.log.debug("HTTP Upgrade header missing : 303-redirecting to %s" % url)
|
||||
self.sendRedirect(url)
|
||||
else:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("HTTP Upgrade header missing : render server status page")
|
||||
self.log.debug("HTTP Upgrade header missing : render server status page")
|
||||
self.sendServerStatus()
|
||||
self.dropConnection(abort=False)
|
||||
return
|
||||
@@ -2605,12 +2562,10 @@ class WebSocketServerProtocol(WebSocketProtocol):
|
||||
# Sec-WebSocket-Version PLUS determine mode: Hybi or Hixie
|
||||
#
|
||||
if 'sec-websocket-version' not in self.http_headers:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("Hixie76 protocol detected")
|
||||
self.log.debug("Hixie76 protocol detected")
|
||||
return self.failHandshake("WebSocket connection denied - Hixie76 protocol not supported.")
|
||||
else:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("Hybi protocol detected")
|
||||
self.log.debug("Hybi protocol detected")
|
||||
if http_headers_cnt["sec-websocket-version"] > 1:
|
||||
return self.failHandshake("HTTP Sec-WebSocket-Version header appears more than once in opening handshake request")
|
||||
try:
|
||||
@@ -2893,8 +2848,7 @@ class WebSocketServerProtocol(WebSocketProtocol):
|
||||
# cancel any opening HS timer if present
|
||||
#
|
||||
if self.openHandshakeTimeoutCall is not None:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("openHandshakeTimeoutCall.cancel")
|
||||
self.log.debug("openHandshakeTimeoutCall.cancel")
|
||||
self.openHandshakeTimeoutCall.cancel()
|
||||
self.openHandshakeTimeoutCall = None
|
||||
|
||||
@@ -3033,8 +2987,7 @@ class WebSocketServerFactory(WebSocketFactory):
|
||||
server="AutobahnPython/%s" % __version__,
|
||||
headers=None,
|
||||
externalPort=None,
|
||||
debug=False,
|
||||
debugCodePaths=False):
|
||||
debug=False):
|
||||
"""
|
||||
Create instance of WebSocket server factory.
|
||||
|
||||
@@ -3052,11 +3005,8 @@ class WebSocketServerFactory(WebSocketFactory):
|
||||
:type externalPort: int
|
||||
:param debug: Debug mode (default: `False`).
|
||||
:type debug: bool
|
||||
:param debugCodePaths: Debug code paths mode (default: `False`).
|
||||
:type debugCodePaths: bool
|
||||
"""
|
||||
self.debug = debug
|
||||
self.debugCodePaths = debugCodePaths
|
||||
|
||||
self.logOctets = debug
|
||||
self.logFrames = debug
|
||||
@@ -3697,8 +3647,7 @@ class WebSocketClientProtocol(WebSocketProtocol):
|
||||
# cancel any opening HS timer if present
|
||||
#
|
||||
if self.openHandshakeTimeoutCall is not None:
|
||||
if self.debugCodePaths:
|
||||
self.log.debug("openHandshakeTimeoutCall.cancel")
|
||||
self.log.debug("openHandshakeTimeoutCall.cancel")
|
||||
self.openHandshakeTimeoutCall.cancel()
|
||||
self.openHandshakeTimeoutCall = None
|
||||
|
||||
@@ -3773,8 +3722,7 @@ class WebSocketClientFactory(WebSocketFactory):
|
||||
useragent="AutobahnPython/%s" % __version__,
|
||||
headers=None,
|
||||
proxy=None,
|
||||
debug=False,
|
||||
debugCodePaths=False):
|
||||
debug=False):
|
||||
"""
|
||||
Create instance of WebSocket client factory.
|
||||
|
||||
@@ -3798,11 +3746,8 @@ class WebSocketClientFactory(WebSocketFactory):
|
||||
:type proxy: dict or None
|
||||
:param debug: Debug mode (default: `False`).
|
||||
:type debug: bool
|
||||
:param debugCodePaths: Debug code paths mode (default: `False`).
|
||||
:type debugCodePaths: bool
|
||||
"""
|
||||
self.debug = debug
|
||||
self.debugCodePaths = debugCodePaths
|
||||
|
||||
self.logOctets = debug
|
||||
self.logFrames = debug
|
||||
|
||||
@@ -211,11 +211,6 @@ if os.environ.get('USE_TWISTED', False):
|
||||
"""
|
||||
autoping and autoping-timeout timing
|
||||
"""
|
||||
if False:
|
||||
self.proto.debug = True
|
||||
self.proto.factory._log = print
|
||||
self.proto.debugCodePaths = True
|
||||
|
||||
# options are evaluated in succeedHandshake, called below
|
||||
self.proto.autoPingInterval = 5
|
||||
self.proto.autoPingTimeout = 2
|
||||
@@ -265,11 +260,6 @@ if os.environ.get('USE_TWISTED', False):
|
||||
"""
|
||||
auto-ping with correct reply cancels timeout
|
||||
"""
|
||||
if False:
|
||||
self.proto.debug = True
|
||||
self.proto.factory._log = print
|
||||
self.proto.debugCodePaths = True
|
||||
|
||||
# options are evaluated in succeedHandshake, called below
|
||||
self.proto.autoPingInterval = 5
|
||||
self.proto.autoPingTimeout = 2
|
||||
|
||||
@@ -63,12 +63,12 @@ class TesteeServerFactory(WebSocketServerFactory):
|
||||
# protocol = TesteeServerProtocol
|
||||
protocol = StreamingTesteeServerProtocol
|
||||
|
||||
def __init__(self, url, debug=False, ident=None):
|
||||
def __init__(self, url, ident=None):
|
||||
if ident is not None:
|
||||
server = ident
|
||||
else:
|
||||
server = "AutobahnPython-Asyncio/%s" % autobahn.version
|
||||
WebSocketServerFactory.__init__(self, url, debug=debug, debugCodePaths=debug, server=server)
|
||||
WebSocketServerFactory.__init__(self, url, server=server)
|
||||
self.setProtocolOptions(failByDrop=False) # spec conformance
|
||||
self.setProtocolOptions(failByDrop=True) # needed for streaming mode
|
||||
# self.setProtocolOptions(utf8validateIncoming = False)
|
||||
@@ -91,7 +91,7 @@ if __name__ == '__main__':
|
||||
# Trollius >= 0.3 was renamed
|
||||
import trollius as asyncio
|
||||
|
||||
factory = TesteeServerFactory(u"ws://127.0.0.1:9002", debug=False)
|
||||
factory = TesteeServerFactory(u"ws://127.0.0.1:9002")
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
coro = loop.create_server(factory, port=9002)
|
||||
|
||||
@@ -58,8 +58,8 @@ class BroadcastServerFactory(WebSocketServerFactory):
|
||||
currently connected clients.
|
||||
"""
|
||||
|
||||
def __init__(self, url, debug=False, debugCodePaths=False):
|
||||
WebSocketServerFactory.__init__(self, url, debug=debug, debugCodePaths=debugCodePaths)
|
||||
def __init__(self, url):
|
||||
WebSocketServerFactory.__init__(self, url)
|
||||
self.clients = []
|
||||
self.tickcount = 0
|
||||
self.tick()
|
||||
@@ -103,19 +103,12 @@ class BroadcastPreparedServerFactory(BroadcastServerFactory):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
ServerFactory = BroadcastServerFactory
|
||||
# ServerFactory = BroadcastPreparedServerFactory
|
||||
|
||||
factory = ServerFactory(u"ws://127.0.0.1:9000",
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
|
||||
factory = ServerFactory(u"ws://127.0.0.1:9000")
|
||||
factory.protocol = BroadcastServerProtocol
|
||||
listenWS(factory)
|
||||
|
||||
|
||||
@@ -62,20 +62,12 @@ if __name__ == '__main__':
|
||||
print("Need the WebSocket server address, i.e. ws://127.0.0.1:9000")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) > 2 and sys.argv[2] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
|
||||
factory = WebSocketClientFactory(sys.argv[1],
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
factory = WebSocketClientFactory(sys.argv[1])
|
||||
factory.protocol = EchoClientProtocol
|
||||
|
||||
# Enable WebSocket extension "permessage-deflate".
|
||||
##
|
||||
|
||||
# The extensions offered to the server ..
|
||||
offers = [PerMessageDeflateOffer()]
|
||||
@@ -89,6 +81,5 @@ if __name__ == '__main__':
|
||||
factory.setProtocolOptions(perMessageCompressionAccept=accept)
|
||||
|
||||
# run client
|
||||
##
|
||||
connectWS(factory)
|
||||
reactor.run()
|
||||
|
||||
@@ -59,15 +59,9 @@ if __name__ == '__main__':
|
||||
print "Need the WebSocket server address, i.e. ws://127.0.0.1:9000"
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) > 2 and sys.argv[2] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
factory = WebSocketClientFactory(sys.argv[1],
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
factory = WebSocketClientFactory(sys.argv[1])
|
||||
|
||||
factory.protocol = EchoClientProtocol
|
||||
|
||||
|
||||
@@ -53,20 +53,12 @@ class EchoServerProtocol(WebSocketServerProtocol):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
|
||||
factory = WebSocketServerFactory(u"ws://127.0.0.1:9000",
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
factory = WebSocketServerFactory(u"ws://127.0.0.1:9000")
|
||||
factory.protocol = EchoServerProtocol
|
||||
|
||||
# Enable WebSocket extension "permessage-deflate".
|
||||
##
|
||||
|
||||
# Function to accept offers from the client ..
|
||||
def accept(offers):
|
||||
@@ -77,7 +69,6 @@ if __name__ == '__main__':
|
||||
factory.setProtocolOptions(perMessageCompressionAccept=accept)
|
||||
|
||||
# run server
|
||||
##
|
||||
listenWS(factory)
|
||||
|
||||
webdir = File(".")
|
||||
|
||||
@@ -52,23 +52,15 @@ class EchoServerProtocol(WebSocketServerProtocol):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
|
||||
factory = WebSocketServerFactory(u"ws://127.0.0.1:9000",
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
factory = WebSocketServerFactory(u"ws://127.0.0.1:9000")
|
||||
factory.protocol = EchoServerProtocol
|
||||
|
||||
# factory.setProtocolOptions(autoFragmentSize = 4)
|
||||
|
||||
# Enable WebSocket extension "permessage-deflate". This is all you
|
||||
# need to do (unless you know what you are doing .. see below)!
|
||||
##
|
||||
def accept0(offers):
|
||||
for offer in offers:
|
||||
if isinstance(offer, PerMessageDeflateOffer):
|
||||
@@ -76,7 +68,6 @@ if __name__ == '__main__':
|
||||
|
||||
# Enable experimental compression extensions "permessage-snappy"
|
||||
# and "permessage-bzip2"
|
||||
##
|
||||
def accept1(offers):
|
||||
for offer in offers:
|
||||
if isinstance(offer, PerMessageSnappyOffer):
|
||||
@@ -90,7 +81,6 @@ if __name__ == '__main__':
|
||||
|
||||
# permessage-deflate, server requests the client to do no
|
||||
# context takeover
|
||||
##
|
||||
def accept2(offers):
|
||||
for offer in offers:
|
||||
if isinstance(offer, PerMessageDeflateOffer):
|
||||
@@ -99,7 +89,6 @@ if __name__ == '__main__':
|
||||
|
||||
# permessage-deflate, server requests the client to do no
|
||||
# context takeover, and does not context takeover also
|
||||
##
|
||||
def accept3(offers):
|
||||
for offer in offers:
|
||||
if isinstance(offer, PerMessageDeflateOffer):
|
||||
@@ -108,7 +97,6 @@ if __name__ == '__main__':
|
||||
|
||||
# permessage-deflate, server requests the client to do use
|
||||
# max window bits specified
|
||||
##
|
||||
def accept4(offers):
|
||||
for offer in offers:
|
||||
if isinstance(offer, PerMessageDeflateOffer):
|
||||
|
||||
@@ -57,19 +57,11 @@ if __name__ == '__main__':
|
||||
print("Need the WebSocket server address, i.e. ws://127.0.0.1:9000")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) > 2 and sys.argv[2] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
headers = {'MyCustomClientHeader': 'Bazbar'}
|
||||
|
||||
factory = WebSocketClientFactory(sys.argv[1],
|
||||
headers=headers,
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
|
||||
factory = WebSocketClientFactory(sys.argv[1], headers=headers)
|
||||
factory.protocol = EchoClientProtocol
|
||||
connectWS(factory)
|
||||
|
||||
|
||||
@@ -57,19 +57,11 @@ class EchoServerProtocol(WebSocketServerProtocol):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
headers = {'MyCustomServerHeader': 'Foobar'}
|
||||
|
||||
factory = WebSocketServerFactory(u"ws://127.0.0.1:9000",
|
||||
headers=headers,
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
|
||||
factory = WebSocketServerFactory(u"ws://127.0.0.1:9000")
|
||||
factory.protocol = EchoServerProtocol
|
||||
listenWS(factory)
|
||||
|
||||
|
||||
@@ -208,8 +208,8 @@ class EchoServerFactory(WebSocketServerFactory):
|
||||
|
||||
protocol = EchoServerProtocol
|
||||
|
||||
def __init__(self, wsuri, debug=False):
|
||||
WebSocketServerFactory.__init__(self, wsuri, debug=debug, debugCodePaths=debug)
|
||||
def __init__(self, wsuri):
|
||||
WebSocketServerFactory.__init__(self, wsuri)
|
||||
self.stats = Stats()
|
||||
|
||||
|
||||
@@ -283,7 +283,7 @@ def worker(options):
|
||||
p.cpu_affinity([options.cpuid])
|
||||
print "affinity [after]", p.cpu_affinity()
|
||||
|
||||
factory = EchoServerFactory(options.wsuri, debug=options.debug)
|
||||
factory = EchoServerFactory(options.wsuri)
|
||||
|
||||
# The master already created the socket, just start listening and accepting
|
||||
##
|
||||
|
||||
@@ -48,15 +48,9 @@ class EchoServerProtocol(WebSocketServerProtocol):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
factory = WebSocketServerFactory(u"ws://127.0.0.1:8080",
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
factory = WebSocketServerFactory(u"ws://127.0.0.1:8080")
|
||||
factory.protocol = EchoServerProtocol
|
||||
|
||||
resource = WebSocketResource(factory)
|
||||
|
||||
@@ -45,18 +45,12 @@ class EchoServerProtocol(WebSocketServerProtocol):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
contextFactory = ssl.DefaultOpenSSLContextFactory('keys/server.key',
|
||||
'keys/server.crt')
|
||||
|
||||
factory = WebSocketServerFactory(u"wss://127.0.0.1:8080",
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
factory = WebSocketServerFactory(u"wss://127.0.0.1:8080")
|
||||
factory.protocol = EchoServerProtocol
|
||||
|
||||
resource = WebSocketResource(factory)
|
||||
|
||||
@@ -44,21 +44,14 @@ class EchoServerProtocol(WebSocketServerProtocol):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
# SSL server context: load server key and certificate
|
||||
# We use this for both WS and Web!
|
||||
#
|
||||
contextFactory = ssl.DefaultOpenSSLContextFactory('keys/server.key',
|
||||
'keys/server.crt')
|
||||
|
||||
factory = WebSocketServerFactory(u"wss://127.0.0.1:9000",
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
factory = WebSocketServerFactory(u"wss://127.0.0.1:9000")
|
||||
|
||||
factory.protocol = EchoServerProtocol
|
||||
listenWS(factory, contextFactory)
|
||||
|
||||
@@ -54,15 +54,9 @@ if __name__ == '__main__':
|
||||
print("Need the WebSocket server address, i.e. ws://127.0.0.1:9000")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) > 2 and sys.argv[2] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
factory = WebSocketClientFactory(sys.argv[1],
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
factory = WebSocketClientFactory(sys.argv[1])
|
||||
factory.protocol = EchoClientProtocol
|
||||
connectWS(factory)
|
||||
|
||||
|
||||
@@ -76,15 +76,9 @@ if __name__ == '__main__':
|
||||
print("Need the WebSocket server address, i.e. ws://127.0.0.1:9000")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) > 2 and sys.argv[2] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
factory = EchoClientFactory(sys.argv[1],
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
factory = EchoClientFactory(sys.argv[1])
|
||||
connectWS(factory)
|
||||
|
||||
reactor.run()
|
||||
|
||||
@@ -61,16 +61,9 @@ if __name__ == '__main__':
|
||||
proxyHost, proxyPort = sys.argv[2].split(":")
|
||||
proxy = {'host': proxyHost, 'port': int(proxyPort)}
|
||||
|
||||
if len(sys.argv) > 3 and sys.argv[3] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
factory = WebSocketClientFactory(sys.argv[1],
|
||||
proxy=proxy,
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
factory = WebSocketClientFactory(sys.argv[1], proxy=proxy)
|
||||
factory.protocol = EchoClientProtocol
|
||||
connectWS(factory)
|
||||
|
||||
|
||||
@@ -44,16 +44,9 @@ class EchoServerProtocol(WebSocketServerProtocol):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
|
||||
factory = WebSocketServerFactory(u"ws://127.0.0.1:9000",
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
factory = WebSocketServerFactory(u"ws://127.0.0.1:9000")
|
||||
factory.protocol = EchoServerProtocol
|
||||
listenWS(factory)
|
||||
|
||||
|
||||
@@ -46,32 +46,22 @@ class EchoServerProtocol(WebSocketServerProtocol):
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
wsPort = 9000
|
||||
|
||||
# Our WebSocket server
|
||||
##
|
||||
factory = WebSocketServerFactory(u"ws://127.0.0.1:%d" % wsPort,
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
|
||||
factory = WebSocketServerFactory(u"ws://127.0.0.1:%d" % wsPort)
|
||||
factory.protocol = EchoServerProtocol
|
||||
listenWS(factory)
|
||||
|
||||
# We need to start a "Flash Policy Server" on TCP/843
|
||||
# which Adobe Flash player will contact to check if
|
||||
# it is allowed to connect to the WebSocket port.
|
||||
##
|
||||
flashPolicyFactory = FlashPolicyFactory()
|
||||
reactor.listenTCP(843, flashPolicyFactory)
|
||||
|
||||
# Static Web server
|
||||
##
|
||||
webdir = File("./web")
|
||||
web = Site(webdir)
|
||||
reactor.listenTCP(8080, web)
|
||||
|
||||
@@ -40,18 +40,14 @@ from autobahn.twisted.websocket import WebSocketServerFactory, \
|
||||
from autobahn.twisted.resource import WebSocketResource, WSGIRootResource
|
||||
|
||||
|
||||
##
|
||||
# Our WebSocket Server protocol
|
||||
##
|
||||
class EchoServerProtocol(WebSocketServerProtocol):
|
||||
|
||||
def onMessage(self, payload, isBinary):
|
||||
self.sendMessage(payload, isBinary)
|
||||
|
||||
|
||||
##
|
||||
# Our WSGI application .. in this case Flask based
|
||||
##
|
||||
app = Flask(__name__)
|
||||
app.secret_key = str(uuid.uuid4())
|
||||
|
||||
@@ -63,40 +59,21 @@ def page_home():
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
|
||||
log.startLogging(sys.stdout)
|
||||
debug = True
|
||||
else:
|
||||
debug = False
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
app.debug = debug
|
||||
if debug:
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
##
|
||||
# create a Twisted Web resource for our WebSocket server
|
||||
##
|
||||
wsFactory = WebSocketServerFactory(u"ws://127.0.0.1:8080",
|
||||
debug=debug,
|
||||
debugCodePaths=debug)
|
||||
|
||||
wsFactory = WebSocketServerFactory(u"ws://127.0.0.1:8080")
|
||||
wsFactory.protocol = EchoServerProtocol
|
||||
wsResource = WebSocketResource(wsFactory)
|
||||
|
||||
##
|
||||
# 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
|
||||
##
|
||||
rootResource = WSGIRootResource(wsgiResource, {'ws': wsResource})
|
||||
|
||||
##
|
||||
# create a Twisted Web Site and run everything
|
||||
##
|
||||
site = Site(rootResource)
|
||||
|
||||
reactor.listenTCP(8080, site)
|
||||
|
||||
@@ -42,7 +42,7 @@ if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
factory = WebSocketServerFactory(u"ws://127.0.0.1:9000", debug=False, debugCodePaths=True)
|
||||
factory = WebSocketServerFactory(u"ws://127.0.0.1:9000")
|
||||
factory.protocol = WebSocketServerProtocol
|
||||
|
||||
factory.setProtocolOptions(autoPingInterval=1, autoPingTimeout=3, autoPingSize=20)
|
||||
|
||||
@@ -80,12 +80,12 @@ class TesteeServerFactory(WebSocketServerFactory):
|
||||
else:
|
||||
protocol = TesteeServerProtocol
|
||||
|
||||
def __init__(self, url, debug=False, ident=None):
|
||||
def __init__(self, url, ident=None):
|
||||
if ident is not None:
|
||||
server = ident
|
||||
else:
|
||||
server = "AutobahnPython-Twisted/%s" % autobahn.__version__
|
||||
WebSocketServerFactory.__init__(self, url, debug=debug, debugCodePaths=debug, server=server)
|
||||
WebSocketServerFactory.__init__(self, url, server=server)
|
||||
|
||||
self.setProtocolOptions(failByDrop=False) # spec conformance
|
||||
|
||||
@@ -113,7 +113,7 @@ if __name__ == '__main__':
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
factory = TesteeServerFactory(u"ws://127.0.0.1:9001", debug=False)
|
||||
factory = TesteeServerFactory(u"ws://127.0.0.1:9001")
|
||||
|
||||
reactor.listenTCP(9001, factory)
|
||||
reactor.run()
|
||||
|
||||
Reference in New Issue
Block a user