pub struct Networker<T: NetworkContent + 'static, E: HandlerError> { /* private fields */ }
Expand description
This struct is the main API for using netty. It allows the creation of a server and the ability to send messages to clients.
Implementations§
Source§impl<T: NetworkContent, E: HandlerError> Networker<T, E>
impl<T: NetworkContent, E: HandlerError> Networker<T, E>
Sourcepub async fn new<H, M, FH, FM>(
address: SocketAddr,
directory_service: impl DirectoryService<String, E> + 'static,
handle_handshakes: H,
handle_messages: M,
) -> Result<Networker<T, E>, Error<E>>
pub async fn new<H, M, FH, FM>( address: SocketAddr, directory_service: impl DirectoryService<String, E> + 'static, handle_handshakes: H, handle_messages: M, ) -> Result<Networker<T, E>, Error<E>>
Creates a new networker using. address
is the network socket address that the server should
listen to. directory_service
is the directory service to use in order to translate IDs to
addresses. handle_handshakes
is a closure that is called when a new connection is
recieved which sends a NetworkMessage
. This closure should authenticate if appropriate
and do other handshake and setup related things. handle_messages
is a closure that is
called for all messages received from a connection that has already been handshaked.
Sourcepub async fn send_message(
&self,
message: NetworkMessage<T>,
timeout: Option<Duration>,
react: Option<Action<T, E>>,
) -> Result<(), Error<E>>
pub async fn send_message( &self, message: NetworkMessage<T>, timeout: Option<Duration>, react: Option<Action<T, E>>, ) -> Result<(), Error<E>>
Sends a message and then reacts to the response with the action and then returns the last message returned