#tcp-server #server #tcp #mud

mudbase_server

A library for configuring and running a simple TCP server

1 unstable release

0.1.0 Mar 3, 2022

#10 in #mud


Used in mudbase

MIT license

9KB
73 lines

Mudbase Server

mudbase_server is a sub-module of the Mudbase library that makes it
easier to start and configure a simple TCP server.

Example

use mudbase::server::{ ServerHandler, Sessions, SessionsType };

struct Server {
    sessions: SessionsType,
}

impl Server {
    fn new() -> Self {
        Self {
            sessions: Sessions::new(),
        }
    }
}

impl ServerHandler for Server {
    fn handle_message(message: &str, address: &str) {
      print!("{} says: {}", address, message);  
    }
}

fn main() {
    let server = Server::new();
    let listener = server.start("127.0.0.1", "7878");
    let sessions = server.sessions.clone();

    server.listen(listener, sessions);
}

No runtime deps