src.game_client.connection package

Submodules

src.game_client.connection.establisher module

Module containing ConnectionEstablisher class, which is responsible for instantiating connection to the server by performing a three-way handshake with it.

class src.game_client.connection.establisher.ConnectionEstablisher[source]

Bases: object

Class implementing connection establishment logic.

The class is responsible for establishing the connection to the server, and the session with another remote machine via the server.

establish()[source]

Establish connection to the server and to the other remote player.

Tries to connect to the server by sending a request and waiting for a response. If the server does not respond immediately, it means that there is no waiting client on the server. If the server responds in a desirable way, the three-way handshake is performed.

Returns:

True if connection was successfully established, False otherwise.

Raises:
  • core.utils.exc.ServerUnreachableError – if there was no response from the
  • server or the server was full.
  • core.utils.exc.ProtocolError – if the message received from the server
  • was not recognized as the valid message.
sock

src.game_client.connection.manager module

Module containing ConnectionManager class, which takes care of the connection after it has been established in the earlier stage, and maintains it throughout the entire duration of the session. ConnectionManager runs as a separate thread in the client program.

class src.game_client.connection.manager.ConnectionManager(sock)[source]

Bases: threading.Thread

Class responsible for managing the connection.

Class that takes care of the communication with the server after the connection has been established. Must be created and used after the ConnectionEstablisher succeeds in connecting. Extends threading.Thread.

run()[source]

Main function of the ConnectionManager class.

Manage the connection. This basically comes down to two main tasks: regularly notifying the server that the client is still connected and receiving the server’s orders in the meantime. The ‘IDLE’ message is being sent to the client every few seconds.

Module contents

Package that includes connection establishment and management utilities for the client program. It contains two modules: establisher.py and manager.py. The establisher module contains definition of the ConnectionEstablisher class, while the manager module contains definition of the ConnectionManager class. The difference between the responsibilities of these two classes is mainly that the ConnectionEstablisher class takes care of instantiating the connection, making sure to follow the shared protocol, and the ConnectionManager handles already established connection throughout the duration of the entire session.