Crate linebased[−][src]
Drop-in TCP command server
Provide a callback that is passed commands from clients and handle them synchronously.
mio
is used internally so multiple clients may be active.
Examples
use linebased::Server; // Create a server with the default config and a // handler that only knows the "version" command let mut server = Server::new(Default::default(), |query| { match query { "version" => String::from("0.1.0"), _ => String::from("unknown command"), } }).unwrap(); server.run().unwrap();
Running a server from a separate thread is also possible. Request a handle from the server so that you may shut it down gracefully.
use linebased::Server; use std::thread; let mut server = Server::new(Default::default(), |query| { match query { "version" => String::from("0.1.0"), _ => String::from("unknown command"), } }).unwrap(); let handle = server.handle(); let thread = thread::spawn(move || server.run().unwrap()); // Time passes handle.shutdown().unwrap(); thread.join().unwrap();
Structs
Config |
Server configuration |
Handle |
Handle for the server |
Server |
The linebased TCP server |
Enums
Error |
Error from linebased crate |
Type Definitions
Result |
Results from linebased crate |