pub struct SimpleServer<ServiceT: SimpleService> { /* private fields */ }Expand description
A simple server that handles client connections and manages the application service implementing the SimpleService trait.
The server listens for incoming connections and spawns a new thread for each new client.
§Example: Self-Signed
ⓘ
let (key, private_key) = crate::cert::self_signed(&["localhost"])?;
let config = ServerConfig::builder()
.with_no_client_auth()
.with_single_cert(vec![key.cert.der().clone()], private_key)?;
let server = SimpleServer::new(config);
server.serve()?Implementations§
Source§impl<ServiceT: SimpleService> SimpleServer<ServiceT>
impl<ServiceT: SimpleService> SimpleServer<ServiceT>
Sourcepub fn new(service: ServiceT, config: ServerConfig) -> Self
pub fn new(service: ServiceT, config: ServerConfig) -> Self
Creates a new SimpleServer instance with the provided server configuration.
The ServerConfig is used to configure the TLS settings for the server.
Sourcepub fn serve(self) -> Result<()>
pub fn serve(self) -> Result<()>
Starts the server and listens for incoming connections on the default port (1122).
This method blocks until the server is stopped or an error occurs.
Sourcepub fn serve_port(self, port: u16) -> Result<()>
pub fn serve_port(self, port: u16) -> Result<()>
Starts the server and listens for incoming connections on the specified port.
This method blocks until the server is stopped or an error occurs.
Trait Implementations§
Source§impl<ServiceT: Clone + SimpleService> Clone for SimpleServer<ServiceT>
impl<ServiceT: Clone + SimpleService> Clone for SimpleServer<ServiceT>
Source§fn clone(&self) -> SimpleServer<ServiceT>
fn clone(&self) -> SimpleServer<ServiceT>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<ServiceT> !RefUnwindSafe for SimpleServer<ServiceT>
impl<ServiceT> !UnwindSafe for SimpleServer<ServiceT>
impl<ServiceT> Freeze for SimpleServer<ServiceT>where
ServiceT: Freeze,
impl<ServiceT> Send for SimpleServer<ServiceT>
impl<ServiceT> Sync for SimpleServer<ServiceT>
impl<ServiceT> Unpin for SimpleServer<ServiceT>where
ServiceT: Unpin,
impl<ServiceT> UnsafeUnpin for SimpleServer<ServiceT>where
ServiceT: UnsafeUnpin,
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