Skip to main content

UdpSession

Trait UdpSession 

Source
pub trait UdpSession: Send + 'static {
    // Required method
    fn on_datagram(
        &mut self,
        cx: &mut UdpContext<'_>,
        from: SocketAddr,
        bytes: &[u8],
    );
}
Available on crate feature udp only.
Expand description

A datagram protocol run by a server: one per UDP listener, called on that listener’s thread, so it needs no locks of its own. Budgets and the amplification guard apply before it sees a datagram and on every reply.

use std::net::SocketAddr;
use net_io::{UdpContext, UdpSession};
struct Echo;
impl UdpSession for Echo {
    fn on_datagram(&mut self, cx: &mut UdpContext<'_>, from: SocketAddr, bytes: &[u8]) {
        let _ = cx.send_to(bytes, from);
    }
}

Required Methods§

Source

fn on_datagram( &mut self, cx: &mut UdpContext<'_>, from: SocketAddr, bytes: &[u8], )

One datagram that passed its budgets.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§