Networking Functions

A Networking Function is reusable function designed to perform a specific task or operation related to Networking.

1. Get Peer Id

peer_get_id_async()

Get the id of the current client.

Returns:

  • A str representing the id of the peer.

Example


id = await peer_get_id_async()
print(id)
Run

2. Create Peer Connection

peer_create_connection_async(peerId: str)

Create a connection with destination client identified by peerId asynchronously

Parameters:

  • peerId (str): Peer Id of the destination client to connect with.

Returns:

  • A str representing the id of the connection.

Example


id = await input_async("Peer Id")

conn = await peer_create_connection_async(id)
print(conn)
Run

3. Send Data to Peer

peer_send(conn: str, data: str)

Function to send data to the destination peer.

Parameters:

  • con (str): A str representing the connnection id.
  • data (str): A str representing the data to send to the destination peer.

Example


id = await input_async("Peer Id")

conn = await peer_create_connection_async(id)
print(conn)
peer_send(conn, "data to send")
Run

4. Recieve Peer Data

peer_recive(data: str)

To recive data the destination peer must declare a function called peer_receive(data: str).

Example

import asyncio

def peer_recive(data):
  print(data)

await asyncio.sleep(10000)
Run