/// Send a message to a specific client
Send a message to a specific client
Send a message to a specific client
pub fn send_message<T: NetworkMessage>(
        &self,
        client_id: ConnectionId,
        message: T,
    ) -> Result<(), NetworkError> {
        let connection = match self.established_connections.get(&client_id) {
            Some(conn) => conn,
            None => return Err(NetworkError::ConnectionNotFound(client_id)),
        };
        let packet = NetworkPacket {
            kind: String::from(T::NAME),
            data: bincode::serialize(&message).map_err(|_| NetworkError::Serialization)?,
        };
        match connection.send_message.try_send(packet) {
            Ok(_) => (),
            Err(err) => {
                error!("There was an error sending a packet: {}", err);
                return Err(NetworkError::ChannelClosed(client_id));
            }
        }
        Ok(())
    }
pub fn send_message < T : NetworkMessage > ( & self , client_id : ConnectionId , message : T , ) -> Result < ( ) , NetworkError > { let connection = match self . established_connections . get ( & client_id ) { Some ( conn ) => conn , None => return Err ( NetworkError :: ConnectionNotFound ( client_id ) ) , } ; let packet = NetworkPacket { kind : String :: from ( T :: NAME ) , data : bincode :: serialize ( & message ) . map_err ( | _ | NetworkError :: Serialization ) ? , } ; match connection . send_message . try_send ( packet ) { Ok ( _ ) => ( ) , Err ( err ) => { error ! ( " " err ) ; return Err ( NetworkError :: ChannelClosed ( client_id ) ) ; } } Ok ( ( ) ) }
Send a message to a specific client
Send a message to a specific client
&self
client_id
ConnectionId
message
T