diplomacy.client.connection

Connection object, handling an internal websocket tornado connection.

diplomacy.client.connection.connect(hostname, port)[source]

Connect to given hostname and port.

Parameters:
  • hostname (str) – a hostname
  • port (int) – a port
Returns:

a Connection object connected.

Return type:

Connection

class diplomacy.client.connection.Connection(hostname, port, use_ssl=False)[source]

Bases: object

Connection class.

The connection class should not be initiated directly, but through the connect method

>>> from diplomacy.client.connection import connect
>>> connection = await connect(hostname, port)

Properties:

  • hostname: str hostname to connect (e.g. ‘localhost’)
  • port: int port to connect (e.g. 8888)
  • use_ssl: bool telling if connection should be securized (True) or not (False).
  • url: (property) str websocket url to connect (generated with hostname and port)
  • connection: tornado.websocket.WebSocketClientConnection a tornado websocket connection object
  • connection_count: int number of successful connections from this Connection object. Used to check if message callbacks is already launched (if count > 0).
  • is_connecting: tornado.locks.Event a tornado Event used to keep connection status. No request can be sent while is_connecting. If connected, Synchronize requests can be sent immediately even if is_reconnecting. Other requests must wait full reconnection.
  • is_reconnecting: tornado.locks.Event a tornado Event used to keep re-connection status. Non-synchronize request cannot be sent while is_reconnecting. If reconnected, all requests can be sent.
  • channels: a weakref.WeakValueDictionary mapping channel token to Channel object.
  • requests_to_send: a Dict mapping a request ID to the context of a request not sent. If we are disconnected when trying to send a request, then request context is added to this dictionary to be send later once reconnected.
  • requests_waiting_responses: a Dict mapping a request ID to the context of a request sent. Contains requests that are waiting for a server response.
  • unknown_tokens: set a set of unknown tokens. We can safely ignore them, as the server has been notified.
__init__(hostname, port, use_ssl=False)[source]

Constructor

The connection class should not be initiated directly, but through the connect method

>>> from diplomacy.client.connection import connect
>>> connection = await connect(hostname, port)
Parameters:
  • hostname (str) – hostname to connect (e.g. ‘localhost’)
  • port (int) – port to connect (e.g. 8888)
  • use_ssl (bool) – telling if connection should be securized (True) or not (False).
authenticate(username, password)[source]

Send a SignIn request. User will be created on the server automatically if it doesn’t exist.

Parameters:
  • username (str) – username
  • password (str) – password
Returns:

a Channel object representing the authentication.

Return type:

diplomacy.client.channel.Channel

get_daide_port(game_id)[source]

Send a GetDaidePort request.

Parameters:game_id (str) – game id for which to retrieve the DAIDE port.
Returns:the game DAIDE port
Return type:int