pub struct UtpContext { /* private fields */ }
Expand description
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§
Source§impl UtpContext
impl UtpContext
Sourcepub fn bind(addr: SocketAddr) -> Result<UtpContext>
pub fn bind(addr: SocketAddr) -> Result<UtpContext>
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();
Sourcepub fn listener(&self) -> UtpListener
pub fn listener(&self) -> UtpListener
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(())
}
Sourcepub fn connect(&self, addr: SocketAddr) -> Connect ⓘ
pub fn connect(&self, addr: SocketAddr) -> Connect ⓘ
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)
pub fn clear_mtu(&self)
Auto Trait Implementations§
impl Freeze for UtpContext
impl RefUnwindSafe for UtpContext
impl Send for UtpContext
impl Sync for UtpContext
impl Unpin for UtpContext
impl UnwindSafe for UtpContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more