pub struct Socket { /* private fields */ }Expand description
A connection to a UdpSocket that understands how to send/receive Deliverable. Meant to be used by both Client and Server.
Currently wraps UdpSocket::bind
Implementations§
Source§impl Socket
impl Socket
Sourcepub const MAX_MESSAGE_SIZE: u16 = 548u16
pub const MAX_MESSAGE_SIZE: u16 = 548u16
“A DHCP client must be prepared to receive DHCP messages with an options field of at least length 312 octets”
All other fields add to length 236, so 236 + 312 = 548
Sourcepub const EMPTY_MESSAGE_BUFFER: MessageBuffer
pub const EMPTY_MESSAGE_BUFFER: MessageBuffer
A MessageBuffer with all 0 bytes.
Sourcepub fn new(address: SocketAddrV4, interface: Option<&String>) -> Self
pub fn new(address: SocketAddrV4, interface: Option<&String>) -> Self
Bind to an ip address/port and require that broadcast is enabled on the socket.
Should be be called by both Server::new and Client::new, so this can be slower/panic
since it is not in the listen_once hot path.
Sourcepub fn get_ip(&self) -> Ipv4Addr
pub fn get_ip(&self) -> Ipv4Addr
Returns the ip address of the bound socket.
Can panic as typically called outside of listen_once hot path.
Sourcepub fn receive<M: Decodable<Output = M>>(&self) -> Result<(M, SocketAddr)>
pub fn receive<M: Decodable<Output = M>>(&self) -> Result<(M, SocketAddr)>
Decodes received bytes into a “message” type that implements DecodeMessage
and returns it and the source address.
Sourcepub fn receive_raw(&self) -> Result<(UndecodedMessage, SocketAddr)>
pub fn receive_raw(&self) -> Result<(UndecodedMessage, SocketAddr)>
Returns received bytes directly without being decoded into a Deliverable,
which allows you to partially decode them yourself later.
Sourcepub fn receive_mock(partial_message: &[u8]) -> UndecodedMessage
pub fn receive_mock(partial_message: &[u8]) -> UndecodedMessage
Fills an empty undecoded message with passed bytes.
Used to mock receiving a specific UndecodedMessage in tests, etc.