kubi/kubi-udp/src/server.rs

15 lines
321 B
Rust
Raw Normal View History

2023-01-31 20:16:23 -06:00
use std::net::{UdpSocket, SocketAddr};
use crate::BINCODE_CONFIG;
pub struct Server {
socket: UdpSocket,
}
impl Server {
pub fn bind(addr: SocketAddr) -> anyhow::Result<Self> {
let socket = UdpSocket::bind(addr)?;
socket.set_nonblocking(true)?;
socket.set_broadcast(true)?;
Ok(Self { socket })
}
}