Crate netcode [] [src]

Rust implementation of netcode.io protocol.

This crate contains Server, Client and ConnectToken used to establish a netcode.io session.

Connect Token

Each netcode.io session starts with a ConnectToken. This token is handed out by a HTTPS webserver, authentication server or other private avenue to allow a client to establish a connection with a netcode.io based server. Rather than specifying an address the list of hosts are contained within the token. Note that private keys are included in the clear so HTTPS or other secure measures for delivering the token to the client are required.

Server

The netcode.io server is created within the UDPServer::new(...) call. It accepts a local address, number of clients and private key used to sign the ConnectTokens send to the connecting clients.

Example

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

const PROTOCOL_ID: u64 = 0xFFEE;
const MAX_CLIENTS: usize = 32;
let mut server = UdpServer::new("127.0.0.1:0", MAX_CLIENTS, PROTOCOL_ID, &netcode::generate_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()
    }
//}

Structs

Client

Netcode client object.

ConnectToken

Token used by clients to connect and authenticate to a netcode Server

Server

Netcode server object.

Enums

ClientEvent

Describes event the server receives when calling next_event(..).

ClientState

States represented by the client

InternalError

Errors internal to netcode.

RecvError

Errors from receiving packets

SendError

Errors from sending packets

ServerEvent

Describes event the server receives when calling next_event(..).

UpdateError

Errors from calls to next_event().

Constants

NETCODE_MAX_PACKET_SIZE

Maximum size packet that is sent over the wire.

NETCODE_MAX_PAYLOAD_SIZE

Maximum size of a payload that can be sent(1175).

NETCODE_USER_DATA_BYTES

Maximum size of userdata included in ConnectToken.

Functions

generate_key

Generates a new random private key.

Type Definitions

UdpClient

UDP based netcode client.

UdpServer

UDP based netcode server.