Peer

class Peer(address: str = None, port: int = 0, **kwargs)

Bases: peerpy.event_handler.EventHandler

address

This peer’ address, in a normalized format

Returns:the normalized address (ipv4, port)
Return type:Tuple[str, int]
address_name

This peer’s normalized address name

Returns:the normalized address name ipv4:port
Return type:str
broadcast(data: Any)

Broadcasts data to all the connected peers.

Parameters:data (Any) – the data to broadcast
connect(address: str, port: int = None, data_type: str = 'json', strict: bool = True, **kwargs) → peerpy.connection.Connection

Attempts to start a connection with a remote peer located at (address, port). Additional arguments are passed to the Connection constructor and sent to the remote peer right after successful connection, so that it knows with what data type to communicate with.

Parameters:
  • address (str) – the ipv4 address of the remote peer, provided with the port if wanted (ipv4:port)
  • port (int, optional) – the port to use for the connection, if not provided in address. Defaults to None.
  • data_type (str, optional) – the data type to use for the connection. Defaults to “raw”.
  • strict (bool, optional) – whether this connection is strict on data types. Defaults to True.
  • buffer_size (int, optional) – the buffer size to use to receive data. Defaults to this peer’s buffer size.
Returns:

the connection, if established

Return type:

Connection

get_local_peers() → List[str]

Returns the list of peers visible on the same local network.

Returns:the list of visible peers’ addresses
Return type:List[str]
invisible

Whether this peer is invisible to other peers on the same local network

Returns:this peer’s invisibility
Return type:bool
start()

Attempts to start this peer’s server and pinger (if needed).

stop(_async=False)

Attempts to stop this peer and all its connections.

Parameters:_async (bool, optional) – whether to stop this peer asynchronously. Defaults to False.
timeout

This peer’s default timeout

Returns:the default timeout
Return type:float