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 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: Deliverable<Output = M>>(&self) -> Result<(M, SocketAddr)>
pub fn receive<M: Deliverable<Output = M>>(&self) -> Result<(M, SocketAddr)>
Converts received bytes into a Deliverable and returns it and the source address.
Sourcepub fn unicast<A: ToSocketAddrs, M: Deliverable>(
&self,
message: &M,
address: A,
) -> Result<()>
pub fn unicast<A: ToSocketAddrs, M: Deliverable>( &self, message: &M, address: A, ) -> Result<()>
Converts a message to bytes and then sends it to the passed address.
Auto Trait Implementations§
impl Freeze for Socket
impl RefUnwindSafe for Socket
impl Send for Socket
impl Sync for Socket
impl Unpin for Socket
impl UnwindSafe for Socket
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