Connection¶
-
class
Connection
(peer, target_name: str, sock: socket.socket, buffer_size: int, **kwargs)¶ Bases:
peerpy.event_handler.EventHandler
-
close
(force: bool = False)¶ Closes the connection nicely.
Parameters: - force (bool, optional) – whether to force close the connection.
- setting should be considered dangerous, as data can be lost. Defaults to False. (This) –
-
closed
¶ Returns whether this connection is closed.
Returns: a boolean indicating whether the connection is closed. Return type: bool
-
data_type
¶ Returns the data type each peers have agreed on for this connection.
Returns: the string representation of the data type Return type: str
-
send
(data: Any)¶ Send data to the target peer, serializing it to this connection’s default data format.
Parameters: data (Any) – the data to serialize and send. Raises: ValueError
– if this connection’s default format is bytes and the data is not bytesReturns: whether data was successfully sent. Return type: bool
-
start_thread
()¶ Attempts to start this connection’s main thread, if not already running.
-