pub struct Server<A: ToSocketAddrs + Sync, S: Storage + Sync + Send> { /* private fields */ }
Expand description
A Iridium DirectIP
server.
The server will listen on a socket address for incoming Iridium SBD Mobile Originated
messages. Incoming messages will be stored using sbd::filesystem::Storage
. Errors are logged
using the logging framework.
Implementations§
source§impl<A, S> Server<A, S>where
A: ToSocketAddrs + Sync,
S: 'static + Storage + Sync + Send,
impl<A, S> Server<A, S>where A: ToSocketAddrs + Sync, S: 'static + Storage + Sync + Send,
sourcepub fn new(addr: A, storage: S) -> Server<A, S>
pub fn new(addr: A, storage: S) -> Server<A, S>
Creates a new server that will listen on addr
and write messages to storage
.
This method does not actually bind to the socket address or do anything with the storage.
Use bind
and serve_forever
to actually do stuff.
The provided storage is expected to be ready to accept new messages.
Examples
let storage = sbd::storage::MemoryStorage::new();
let server = sbd::directip::Server::new("0.0.0.0:10800", storage);
sourcepub fn bind(&mut self) -> Result<()>
pub fn bind(&mut self) -> Result<()>
Binds this server to its tcp socket.
This is a seperate operation from serve_forever
so that we can capture any errors
associated with the underlying TcpListener::bind
.
Examples
let storage = sbd::storage::MemoryStorage::new();
let mut server = sbd::directip::Server::new("0.0.0.0:10800", storage);
server.bind().unwrap();
sourcepub fn serve_forever(self)
pub fn serve_forever(self)
Starts the DirectIP server and serves forever.
Panics
This method panics if it has a problem binding to the tcp socket address. To avoid a panic,
use Server::bind
before calling Server::serve_forever
.
Examples
let storage = sbd::storage::MemoryStorage::new();
let mut server = sbd::directip::Server::new("0.0.0.0:10800", storage);
server.bind().unwrap();
server.serve_forever();