[−][src]Struct qp2p::Connection
Connection instance to a node which can be used to send messages to it
Implementations
impl Connection
[src]
pub fn remote_address(&self) -> SocketAddr
[src]
Returns the address of the connected peer.
Example
use qp2p::{QuicP2p, Config, Error}; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; #[tokio::main] async fn main() -> Result<(), Error> { let mut config = Config::default(); config.ip = Some(IpAddr::V4(Ipv4Addr::LOCALHOST)); let mut quic_p2p = QuicP2p::with_config(Some(config.clone()), Default::default(), true)?; let peer_1 = quic_p2p.new_endpoint()?; let peer1_addr = peer_1.our_endpoint()?; let (peer_2, connection) = quic_p2p.connect_to(&peer1_addr).await?; assert_eq!(connection.remote_address(), peer1_addr); Ok(()) }
pub async fn open_bi_stream<'_>(&'_ self) -> Result<(SendStream, RecvStream)>
[src]
Get connection streams for reading/writing
Example
use qp2p::{QuicP2p, Config, Error}; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; #[tokio::main] async fn main() -> Result<(), Error> { let mut config = Config::default(); config.ip = Some(IpAddr::V4(Ipv4Addr::LOCALHOST)); let mut quic_p2p = QuicP2p::with_config(Some(config.clone()), Default::default(), true)?; let peer_1 = quic_p2p.new_endpoint()?; let peer1_addr = peer_1.our_endpoint()?; let (peer_2, connection) = quic_p2p.connect_to(&peer1_addr).await?; let (send_stream, recv_stream) = connection.open_bi_stream().await?; Ok(()) }
pub async fn send<'_>(&'_ self, msg: Bytes) -> Result<(SendStream, RecvStream)>
[src]
Send message to the connected peer via a bi-directional stream. This returns the streams to send additional messages / read responses sent using the same stream.
pub async fn send_uni<'_>(&'_ self, msg: Bytes) -> Result<()>
[src]
Send message to peer using a uni-directional stream.
pub fn close(&self)
[src]
Gracefully close connection immediatelly
Trait Implementations
impl Drop for Connection
[src]
Auto Trait Implementations
impl RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnwindSafe for Connection
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,