examples.multi_transport package

Migration Guide

The libp2p.transport.transport_registry module has been removed, and Swarm no longer accepts the transport= keyword argument.

To migrate to the new TransportManager architecture: - Pass a list of transports to new_swarm or new_host using the transports=[…] keyword argument. - If transports is omitted, the swarm will automatically detect and create transports based on the provided listen_addrs.

Submodules

examples.multi_transport.client module

Multi-Transport Echo Client — py-libp2p

Connects to the multi-transport echo server using whichever transport is encoded in the supplied multiaddress.

Usage:

python client.py -d /ip4/127.0.0.1/tcp/4001/p2p/<PEER_ID> python client.py -d /ip4/127.0.0.1/tcp/4002/ws/p2p/<PEER_ID> python client.py -d /ip4/127.0.0.1/udp/4003/quic/p2p/<PEER_ID>

examples.multi_transport.client.main() None
async examples.multi_transport.client.run_client(destination: str, message: bytes = b'hello from py-libp2p!\n') None

Connect to destination (a full /p2p/… multiaddr), send message, and print the echoed reply.

The client inspects the destination multiaddr to enable the right transport in the Swarm’s TransportManager before dialing.

examples.multi_transport.server module

Multi-Transport Echo Server — py-libp2p

Demonstrates listening on TCP, WebSocket, and QUIC simultaneously, mirroring go-libp2p’s multi-transport architecture.

Usage:

# Start server (auto-detects free ports on all transports): python server.py

# Start server on specific port: python server.py –port 4001

# Start client (copy one of the multiaddrs printed by the server): python client.py -d /ip4/127.0.0.1/tcp/4001/p2p/<PEER_ID> python client.py -d /ip4/127.0.0.1/tcp/4001/ws/p2p/<PEER_ID> python client.py -d /ip4/127.0.0.1/udp/4001/quic/p2p/<PEER_ID>

examples.multi_transport.server.main() None
async examples.multi_transport.server.run_server(port: int = 0) None

Listen simultaneously on TCP, WebSocket, and QUIC using the EXACT SAME PORT. This demonstrates py-libp2p’s connection multiplexing (cmux) capabilities.

Module contents

Multi-transport example package.