Added support for forcing websocket connections if available. Also fixed a small bug that seemed to be causing a race condition on first connections due to a failure to consume a packet on opening the default namespace
This commit is contained in:
parent
5af21af575
commit
ef64649a2a
2 changed files with 10 additions and 3 deletions
|
|
@ -138,11 +138,16 @@ class SocketIO(object):
|
|||
"""
|
||||
|
||||
def __init__(
|
||||
self, host, port=None, Namespace=BaseNamespace,
|
||||
wait_for_connection=True, **kw):
|
||||
self, host,
|
||||
port = None,
|
||||
Namespace = BaseNamespace,
|
||||
wait_for_connection = True,
|
||||
force_websockets_if_available = True,
|
||||
**kw):
|
||||
self.is_secure, self.base_url = _parse_host(host, port)
|
||||
self.wait_for_connection = wait_for_connection
|
||||
self._namespace_by_path = {}
|
||||
self.force_websockets_if_available = force_websockets_if_available;
|
||||
self.kw = kw
|
||||
|
||||
self.__transport = None;
|
||||
|
|
@ -161,6 +166,7 @@ class SocketIO(object):
|
|||
# This sets of a chain of events that attempts to connect to
|
||||
# the server at the base namespace.
|
||||
self.define(Namespace)
|
||||
self._transport.connect("");
|
||||
|
||||
# Events that fail to emit due to connection errors will be
|
||||
# placed in this 'queue' and re-sent automatically upon
|
||||
|
|
@ -497,7 +503,7 @@ class SocketIO(object):
|
|||
# synchronization to ensure buffers are flushed, etc.
|
||||
num_retries = 0;
|
||||
if "websocket" in self.session.server_supported_transports:
|
||||
while num_retries < MAX_UPGRADE_RETRIES:
|
||||
while num_retries < MAX_UPGRADE_RETRIES or self.force_websockets_if_available:
|
||||
try:
|
||||
transport = self._upgrade();
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ class _AbstractTransport(object):
|
|||
self._packets.append(packet);
|
||||
else:
|
||||
self.send_packet(PacketType.OPEN, path, data);
|
||||
self.recv().next();
|
||||
|
||||
def send_heartbeat(self):
|
||||
self.send_packet(PacketType.PING)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue