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:
-
class
diplomacy.client.connection.Connection(hostname, port, use_ssl=False)[source]¶ Bases:
objectConnection 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:
strhostname to connect (e.g. ‘localhost’) - port:
intport to connect (e.g. 8888) - use_ssl:
booltelling if connection should be securized (True) or not (False). - url: (property)
strwebsocket url to connect (generated with hostname and port) - connection:
tornado.websocket.WebSocketClientConnectiona tornado websocket connection object - connection_count:
intnumber of successful connections from this Connection object. Used to check if message callbacks is already launched (if count > 0). - is_connecting:
tornado.locks.Eventa 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.Eventa 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.WeakValueDictionarymapping channel token toChannelobject. - requests_to_send: a
Dictmapping 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
Dictmapping a request ID to the context of a request sent. Contains requests that are waiting for a server response. - unknown_tokens:
seta 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
SignInrequest. User will be created on the server automatically if it doesn’t exist.Parameters: - username (str) – username
- password (str) – password
Returns: a
Channelobject representing the authentication.Return type:
-
get_daide_port(game_id)[source]¶ Send a
GetDaidePortrequest.Parameters: game_id (str) – game id for which to retrieve the DAIDE port. Returns: the game DAIDE port Return type: int
- hostname: