You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reliable is a simple packet acknowledgement system for UDP-based protocols.
It's useful in situations where you need to know which UDP packets you sent were received by the other side.
It has the following features:
Acknowledgement when packets are received
Packet fragmentation and reassembly
RTT, jitter and packet loss estimates
reliable is stable and production ready.
Usage
Reliable is designed to operate with your own network socket library.
If you don't have one already, try netcode, it's designed to work well with reliable.
First, create an endpoint on each side of the connection:
structreliable_config_tconfig;
reliable_default_config( &config );
config.max_packet_size=32*1024;
config.fragment_above=1200;
config.max_fragments=32;
config.fragment_size=1024;
config.transmit_packet_function=transmit_packet;
config.process_packet_function=process_packet;
reliable_endpoint_t*endpoint=reliable_endpoint_create( &config, time );
if ( endpoint==NULL )
{
printf( "error: could not create endpoint\n" );
exit(1);
}
For example, in a client/server setup you would have one endpoint on each client, and n endpoints on the server, one for each client slot.
Next, create a function to transmit packets:
staticvoidtransmit_packet( void*context, uint64_tid, uint16_tsequence, uint8_t*packet_data, intpacket_bytes )
{
// send packet using your own udp socket
}
And a function to process received packets:
staticintprocess_packet( void*context, uint64_tid, uint16_tsequence, uint8_t*packet_data, intpacket_bytes )
{
// read the packet here and process its contents, return 0 if the packet should not be ackedreturn1;
}
For each packet you receive from your udp socket, call this on the endpoint that should receive it:
This way you can map acked sequence numbers to the contents of packets you sent, for example, resending unacked messages until a packet that included that message was acked.
Make sure to update each endpoint once per-frame. This keeps track of network stats like latency, jitter, packet loss and bandwidth: