pub trait ServerSocket:
Debug
+ Send
+ Sync
+ 'static {
// Required methods
fn is_encrypted(&self) -> bool;
fn is_reliable(&self) -> bool;
fn addr(&self) -> Result<SocketAddr>;
fn is_closed(&mut self) -> bool;
fn close(&mut self);
fn connection_denied(&mut self, addr: SocketAddr);
fn connection_accepted(&mut self, client_id: u64, addr: SocketAddr);
fn disconnect(&mut self, addr: SocketAddr);
fn preupdate(&mut self);
fn try_recv(&mut self, buffer: &mut [u8]) -> Result<(usize, SocketAddr)>;
fn postupdate(&mut self);
fn send(
&mut self,
addr: SocketAddr,
packet: &[u8],
) -> Result<(), NetcodeTransportError>;
}Expand description
Unreliable data source for use in NetcodeServerTransport.
Note that while netcode uses SocketAddr everywhere, if your transport uses a different ‘connection URL’
scheme then you can layer the bytes into the ConnectToken server address list.
Just keep in mind that when a client disconnects, the client will traverse the server address list to find
an address to reconnect with. If that isn’t supported by your scheme, then when ServerSocket::send is
called with an invalid/unexpected server address you should return an error. If you want to support
multiple server addresses but your URLs exceed 16 bytes (IPV6 addresses are 16 bytes), then you should pre-parse
the server list from the connect token, and then map that list to the 16-byte IPV6 segments that will be produced
by the client when it tries to reconnect to different servers.
Required Methods§
Sourcefn is_encrypted(&self) -> bool
fn is_encrypted(&self) -> bool
Gets the encryption behavior of the socket.
If the socket internally encrypts packets before sending them, then this should return true.
In that case, renetcode will not pre-encrypt packets before Self::send is called.
Sourcefn is_reliable(&self) -> bool
fn is_reliable(&self) -> bool
Gets the reliability of the socket.
If this is true, then RenetServer will ‘downgrade’ all channels to
SendType::Unreliable so there is not a redundant reliability layer.
Sourcefn addr(&self) -> Result<SocketAddr>
fn addr(&self) -> Result<SocketAddr>
Gets the data source’s SocketAddr.
Returns an error if there is no meaningful address. Server sockets should always have an address.
Sourcefn close(&mut self)
fn close(&mut self)
Closes the data source.
This should disconnect any remote connections that are being tracked.
Sourcefn connection_denied(&mut self, addr: SocketAddr)
fn connection_denied(&mut self, addr: SocketAddr)
Notifies the data source that an address’s connection request was denied.
This can be used to manage fresh connections if the internal socket needs to assign resources to clients. Only connections that are not denied should be assigned resources.
Sourcefn connection_accepted(&mut self, client_id: u64, addr: SocketAddr)
fn connection_accepted(&mut self, client_id: u64, addr: SocketAddr)
Notifies the data source that an address’s connection request was accepted.
This can be used to clean up older sessions tied to the same client id.
Sourcefn disconnect(&mut self, addr: SocketAddr)
fn disconnect(&mut self, addr: SocketAddr)
Disconnects a remote connection with the given address.
Sourcefn preupdate(&mut self)
fn preupdate(&mut self)
Handles data-source-specific logic that must run before receiving packets.
Sourcefn try_recv(&mut self, buffer: &mut [u8]) -> Result<(usize, SocketAddr)>
fn try_recv(&mut self, buffer: &mut [u8]) -> Result<(usize, SocketAddr)>
Tries to receive the next packet sent to this data source.
Returns the number of bytes written to the buffer, and the source address of the bytes.
Should return std::io::ErrorKind::WouldBlock when no packets are available.
Sourcefn postupdate(&mut self)
fn postupdate(&mut self)
Handles data-source-specific logic that must run after sending packets.
Sourcefn send(
&mut self,
addr: SocketAddr,
packet: &[u8],
) -> Result<(), NetcodeTransportError>
fn send( &mut self, addr: SocketAddr, packet: &[u8], ) -> Result<(), NetcodeTransportError>
Sends a packet to the designated address.
Should return std::io::ErrorKind::ConnectionAborted if the destination’s connection was closed internally.