Struct udp_connector::Connector
source · pub struct Connector<TParam: ConnectorParam> { /* private fields */ }
Expand description
The connector is used to handle handshakes and timeouts with a different, remote connector
For client-side applications, we recommend calling update_and_receive
at a frequent rate
For server-side applications, we recommend dealing with your own UdpSocket receiving logic, looking up the connector based on a SocketAddr, and then calling handle_incoming_data
.
The connector struct has a lot of config settings. All these settings can be found in ConnectorParam
Implementations
sourceimpl<TParam: ConnectorParam> Connector<TParam>
impl<TParam: ConnectorParam> Connector<TParam>
sourcepub fn bound_to(peer_addr: SocketAddr) -> Self
pub fn bound_to(peer_addr: SocketAddr) -> Self
Create a Connector that is bound to the given remote SocketAddr
sourcepub fn bound_addr(&self) -> SocketAddr
pub fn bound_addr(&self) -> SocketAddr
Get the socket address that this connector is paired with
sourcepub fn connect(&mut self, socket: &mut dyn Socket) -> Result<()>
pub fn connect(&mut self, socket: &mut dyn Socket) -> Result<()>
Connect to the bound_addr
. This will reset the internal state of the connector, and start up the connection handshake
sourcepub fn state(&self) -> NetworkState
pub fn state(&self) -> NetworkState
Get the current state of this connector. This is dependent on a couple of settings in ConnectorParam:
- If we have received a ping since
ConnectorParam::RECEIVE_PING_TIMEOUT_S
ago, we’re connected - If we have send a ping since
ConnectorParam::SEND_PING_TIMEOUT_S
ago, we’re connecting - Else we’re disconnected
sourcepub fn receive_from(
&mut self,
socket: &mut dyn Socket
) -> Result<Vec<TParam::TReceive>>
pub fn receive_from(
&mut self,
socket: &mut dyn Socket
) -> Result<Vec<TParam::TReceive>>
Receive data from the other connector. This will call handle_incoming_data
internally.
Ideally you would never need this function. Use update_and_receive
on clients, and handle_incoming_data
on servers.
sourcepub fn update_and_receive(
&mut self,
socket: &mut dyn Socket
) -> Result<Vec<TParam::TReceive>>
pub fn update_and_receive(
&mut self,
socket: &mut dyn Socket
) -> Result<Vec<TParam::TReceive>>
Update this connector and receive data from the remote connector.
sourcepub fn update(&mut self, socket: &mut dyn Socket) -> Result<()>
pub fn update(&mut self, socket: &mut dyn Socket) -> Result<()>
Update this connector. This will make sure the connection is still intact and requests any potentially missing packets.
sourcepub fn handle_incoming_data(
&mut self,
socket: &mut dyn Socket,
data: &[u8]
) -> Result<Option<TParam::TReceive>>
pub fn handle_incoming_data(
&mut self,
socket: &mut dyn Socket,
data: &[u8]
) -> Result<Option<TParam::TReceive>>
Handles incoming data. This will perform internal logic to make sure data is being transmitted correctly, and requests missing packets.
Any actual data that was received, will be returned from this function.
sourcepub fn send_unconfirmed(
&mut self,
socket: &mut dyn Socket,
msg: TParam::TSend
) -> Result<()>
pub fn send_unconfirmed(
&mut self,
socket: &mut dyn Socket,
msg: TParam::TSend
) -> Result<()>
Send an unconfirmed message to the other connector. It is not guaranteed that this message will ever arrive.
This is useful for data that does not have to arrive. Think of things like player movements, frames of a lossy video stream, etc.