Struct netcode::Server [] [src]

pub struct Server<I, S> { /* fields omitted */ }

Netcode server object.

Example

use netcode::UdpServer;
use netcode::ServerEvent;

const PROTOCOL_ID: u64 = 0xFFEE;
const MAX_CLIENTS: usize = 32;
let private_key = netcode::generate_key();
let mut server = UdpServer::new("127.0.0.1:0", MAX_CLIENTS, PROTOCOL_ID, &private_key).unwrap();

//loop {
    server.update(1.0 / 10.0);
    let mut packet_data = [0; netcode::NETCODE_MAX_PAYLOAD_SIZE];
    match server.next_event(&mut packet_data) {
        Ok(Some(e)) => {
            match e {
                ServerEvent::ClientConnect(_id) => {},
                ServerEvent::ClientDisconnect(_id) => {},
                ServerEvent::Packet(_id,_size) => {},
                _ => ()
            }
        },
        Ok(None) => (),
        Err(err) => Err(err).unwrap()
    }
//}

Methods

impl<I, S> Server<I, S> where
    I: SocketProvider<I, S>, 
[src]

Constructs a new Server bound to local_addr with max_clients and supplied private_key for authentication.

Generates a connection token with client_id that expires after expire_secs with an optional user_data.

Gets the local port that this server is bound to.

Sends a packet to client_id specified.

Updates time elapsed since last server iteration.

Checks for incoming packets, client connection and disconnections. Returns None when no more events are pending.

Sends a disconnect and removes client.