Struct libutp_rs::UtpContext[][src]

pub struct UtpContext { /* fields omitted */ }

A UTP context

The UtpContext is the core of a UTP application. It sets up the backing UDP socket and provides methods for initiating and accepting connections.

Implementations

impl UtpContext[src]

pub fn bind(addr: SocketAddr) -> Result<UtpContext>[src]

Creates the backing UDP socket and returns a new UtpContext

Example

use libutp_rs::UtpContext;

let ctx = UtpContext::bind("127.0.0.1:5000".parse().unwrap()).unwrap();

pub fn listener(&self) -> UtpListener[src]

Returns a [Stream] of incoming connections.

Example

use libutp_rs::UtpContext;
use std::error::Error;
use futures::stream::StreamExt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let ctx = UtpContext::bind("127.0.0.1:5000".parse()?)?;
    let mut listener = ctx.listener();
    let socket = listener.next().await.unwrap()?;
    Ok(())
}

pub fn connect(&self, addr: SocketAddr) -> Connect

Notable traits for Connect

impl Future for Connect type Output = Result<UtpSocket>;
[src]

Initiates a connection.

Returns a Connect future which resolves to a UtpSocket if successful.

Example

use libutp_rs::UtpContext;
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let ctx = UtpContext::bind("127.0.0.1:5000".parse()?)?;
    let socket = ctx.connect("127.0.0.1:5001".parse()?).await?;
    Ok(())
}

pub fn set_udp_mtu(&self, mtu: u16)[src]

pub fn clear_mtu(&self)[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.