Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/websockets/asyncio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from ..http11 import USER_AGENT, Response
from ..protocol import CONNECTING, Event
from ..streams import StreamReader
from ..typing import LoggerLike, Origin, Subprotocol
from ..typing import Data, LoggerLike, Origin, Subprotocol
from ..uri import Proxy, WebSocketURI, get_proxy, parse_proxy, parse_uri
from .compatibility import TimeoutError, asyncio_timeout
from .connection import Connection
Expand Down Expand Up @@ -55,8 +55,8 @@ class ClientConnection(Connection):
:exc:`~websockets.exceptions.ConnectionClosedError` when the connection is
closed with any other code.

The ``ping_interval``, ``ping_timeout``, ``close_timeout``, ``max_queue``,
and ``write_limit`` arguments have the same meaning as in :func:`connect`.
The ``ping_interval``, ``ping_timeout``, ``ping_data``, ``close_timeout``,
``max_queue`` and ``write_limit`` arguments have the same meaning as in :func:`connect`.

Args:
protocol: Sans-I/O connection.
Expand All @@ -69,6 +69,7 @@ def __init__(
*,
ping_interval: float | None = 20,
ping_timeout: float | None = 20,
ping_data: Data | None = None,
close_timeout: float | None = 10,
max_queue: int | None | tuple[int | None, int | None] = 16,
write_limit: int | tuple[int, int | None] = 2**15,
Expand All @@ -78,6 +79,7 @@ def __init__(
protocol,
ping_interval=ping_interval,
ping_timeout=ping_timeout,
ping_data=ping_data,
close_timeout=close_timeout,
max_queue=max_queue,
write_limit=write_limit,
Expand Down Expand Up @@ -233,6 +235,8 @@ class connect:
:obj:`None` disables keepalive.
ping_timeout: Timeout for keepalive pings in seconds.
:obj:`None` disables timeouts.
ping_data: Payload to send in keepalive pings.
:obj:`None` sends an ramdon bytes ping.
close_timeout: Timeout for closing the connection in seconds.
:obj:`None` disables the timeout.
max_size: Maximum size of incoming messages in bytes.
Expand Down Expand Up @@ -314,6 +318,7 @@ def __init__(
open_timeout: float | None = 10,
ping_interval: float | None = 20,
ping_timeout: float | None = 20,
ping_data: Data | None = None,
close_timeout: float | None = 10,
# Limits
max_size: int | None | tuple[int | None, int | None] = 2**20,
Expand Down Expand Up @@ -357,6 +362,7 @@ def protocol_factory(uri: WebSocketURI) -> ClientConnection:
protocol,
ping_interval=ping_interval,
ping_timeout=ping_timeout,
ping_data=ping_data,
close_timeout=close_timeout,
max_queue=max_queue,
write_limit=write_limit,
Expand Down
6 changes: 4 additions & 2 deletions src/websockets/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ def __init__(
*,
ping_interval: float | None = 20,
ping_timeout: float | None = 20,
ping_data: Data | None = None,
close_timeout: float | None = 10,
max_queue: int | None | tuple[int | None, int | None] = 16,
write_limit: int | tuple[int, int | None] = 2**15,
) -> None:
self.protocol = protocol
self.ping_interval = ping_interval
self.ping_timeout = ping_timeout
self.ping_data = ping_data
self.close_timeout = close_timeout
self.max_queue: tuple[int | None, int | None]
if isinstance(max_queue, int) or max_queue is None:
Expand Down Expand Up @@ -824,8 +826,8 @@ async def keepalive(self) -> None:
# closing because ping(), via send_context(), waits for the
# connection to be closed before raising ConnectionClosed.
# However, connection_lost() cancels keepalive_task before
# it gets a chance to resume excuting.
pong_waiter = await self.ping()
# it gets a chance to resume executing.
pong_waiter = await self.ping(self.ping_data)
if self.debug:
self.logger.debug("% sent keepalive ping")

Expand Down
Loading