pub struct Client<T, C>where
T: Initiator<Connection = C>,
C: Connection,{ /* private fields */ }Expand description
The central client responsible for managing the connection to the server.
This client handles TCP stream creation and delegates UDP session management
to a dedicated UdpDispatcher. It ensures the connection stays alive
through a retry mechanism.
Implementations§
Source§impl<T, C> Client<T, C>where
T: Initiator<Connection = C>,
C: Connection,
impl<T, C> Client<T, C>where
T: Initiator<Connection = C>,
C: Connection,
Sourcepub async fn new(
transport: T,
secret: Secret,
options: Option<Bytes>,
) -> Result<Self>
pub async fn new( transport: T, secret: Secret, options: Option<Bytes>, ) -> Result<Self>
Creates a new Client and establishes a connection to the server.
This involves performing a handshake and spawning a background task to handle incoming UDP datagrams.
Sourcepub async fn open_bidirectional(
&self,
dest_addr: Address,
) -> Result<BufferedStream<C::Stream>>
pub async fn open_bidirectional( &self, dest_addr: Address, ) -> Result<BufferedStream<C::Stream>>
Opens a new bidirectional stream for TCP-like communication.
This method negotiates a new stream with the server, which will then connect to the specified destination address. It waits for the server’s connection response before returning, ensuring proper TCP state handling.
The returned stream is wrapped in a BufferedStream to ensure that any
data remaining in the protocol framing buffer is read first, preventing
data loss when transitioning from message-based to raw stream communication.