Secure client/server protocol for multiplayer games built on top of UDP
C
2,596
1,308 commits
updated Oct 12, 2026
If this library helps you, please support it: Become a supporter
netcode is a secure client/server protocol for multiplayer games built on top of UDP.
Real-time multiplayer games typically use UDP instead of TCP, because head of line blocking delays more recent packets while waiting for older dropped packets to be resent. The problem is that if you want to use UDP, it doesn't provide any concept of connection so you have to build all this yourself, which is a lot of work!
netcode fixes this by providing a minimal and secure connection-oriented protocol on top of UDP, so you can quickly get to exchanging unreliable unordered packets and get busy building the rest of your game network protocol.
Start by generating a random 32 byte private key. Do not share your private key with anybody.
Especially, do not include your private key in your client executable!
Here is a test private key:
static uint8_t private_key[NETCODE_KEY_BYTES] = { 0x60, 0x6a, 0xbe, 0x6e, 0xc9, 0x19, 0x10, 0xea,
0x9a, 0x65, 0x62, 0xf6, 0x6f, 0x2b, 0x30, 0xe4,
0x43, 0x71, 0xd6, 0x2c, 0xd1, 0x99, 0x27, 0x26,
0x6b, 0x3c, 0x60, 0xf4, 0xb7, 0x15, 0xab, 0xa1 };
Create a server with the private key:
char * server_address = "127.0.0.1:40000";
struct netcode_server_config_t server_config;
netcode_default_server_config( &server_config );
server_config.max_connect_token_lifetime = 30;
memcpy( &server_config.private_key, private_key, NETCODE_KEY_BYTES );
struct netcode_server_t * server = netcode_server_create( server_address, &server_config, time );
if ( !server )
{
printf( "error: failed to create server\n" );
return 1;
}
max_connect_token_lifetime is the longest lifetime in seconds your backend issues connect tokens with. The server refuses any connect token that could have been issued before it started, and this is how it knows which those are, so set it to the lifetime your backend uses.
Then start the server with the number of client slots you want:
netcode_server_start( server, 16 );
To connect a client, your client should hit a REST API to your backend that returns a connect token.
There is an example showing how to do this here.
Using a connect token secures your server so that only clients authorized with your backend can connect.
netcode_client_connect( client, connect_token );
Once the client connects to the server, the client is assigned a client index and can exchange encrypted and signed packets with the server.
For more details please see client.c and server.c
This repository holds the implementation of netcode in C.
Other netcode implementations include:
If you'd like to create your own implementation of netcode, please read the netcode 1.02 standard, and see IMPLEMENTERS.md for findings other implementations should check themselves against (a replay-protection overflow and some corrected errata).
These people are awesome:
Thanks for your contributions to netcode!
The author of this library is Glenn Fiedler.
Other open source libraries by the same author include: reliable, serialize, and yojimbo.
If you find this software useful, please consider becoming a supporter. Thanks!
If you use this library in a product, please credit it in your product credits:
netcode - Glenn Fiedler and Rowan Claude
The license doesn't require this. It's an official request, and honoring it is appreciated. Fair credit keeps open source honest.
(top 24 of 36)
2,441 followers · starred Apr 2018
6,679 followers · starred May 2020
150 followers · starred Jul 2026
377 followers · starred Feb 2017
Secure client/server protocol for multiplayer games built on top of UDP
C
2,596
1,308 commits
updated Oct 12, 2026
If this library helps you, please support it: Become a supporter
netcode is a secure client/server protocol for multiplayer games built on top of UDP.
Real-time multiplayer games typically use UDP instead of TCP, because head of line blocking delays more recent packets while waiting for older dropped packets to be resent. The problem is that if you want to use UDP, it doesn't provide any concept of connection so you have to build all this yourself, which is a lot of work!
netcode fixes this by providing a minimal and secure connection-oriented protocol on top of UDP, so you can quickly get to exchanging unreliable unordered packets and get busy building the rest of your game network protocol.
Start by generating a random 32 byte private key. Do not share your private key with anybody.
Especially, do not include your private key in your client executable!
Here is a test private key:
static uint8_t private_key[NETCODE_KEY_BYTES] = { 0x60, 0x6a, 0xbe, 0x6e, 0xc9, 0x19, 0x10, 0xea,
0x9a, 0x65, 0x62, 0xf6, 0x6f, 0x2b, 0x30, 0xe4,
0x43, 0x71, 0xd6, 0x2c, 0xd1, 0x99, 0x27, 0x26,
0x6b, 0x3c, 0x60, 0xf4, 0xb7, 0x15, 0xab, 0xa1 };
Create a server with the private key:
char * server_address = "127.0.0.1:40000";
struct netcode_server_config_t server_config;
netcode_default_server_config( &server_config );
server_config.max_connect_token_lifetime = 30;
memcpy( &server_config.private_key, private_key, NETCODE_KEY_BYTES );
struct netcode_server_t * server = netcode_server_create( server_address, &server_config, time );
if ( !server )
{
printf( "error: failed to create server\n" );
return 1;
}
max_connect_token_lifetime is the longest lifetime in seconds your backend issues connect tokens with. The server refuses any connect token that could have been issued before it started, and this is how it knows which those are, so set it to the lifetime your backend uses.
Then start the server with the number of client slots you want:
netcode_server_start( server, 16 );
To connect a client, your client should hit a REST API to your backend that returns a connect token.
There is an example showing how to do this here.
Using a connect token secures your server so that only clients authorized with your backend can connect.
netcode_client_connect( client, connect_token );
Once the client connects to the server, the client is assigned a client index and can exchange encrypted and signed packets with the server.
For more details please see client.c and server.c
This repository holds the implementation of netcode in C.
Other netcode implementations include:
If you'd like to create your own implementation of netcode, please read the netcode 1.02 standard, and see IMPLEMENTERS.md for findings other implementations should check themselves against (a replay-protection overflow and some corrected errata).
These people are awesome:
Thanks for your contributions to netcode!
The author of this library is Glenn Fiedler.
Other open source libraries by the same author include: reliable, serialize, and yojimbo.
If you find this software useful, please consider becoming a supporter. Thanks!
If you use this library in a product, please credit it in your product credits:
netcode - Glenn Fiedler and Rowan Claude
The license doesn't require this. It's an official request, and honoring it is appreciated. Fair credit keeps open source honest.
(top 24 of 36)
2,441 followers · starred Apr 2018
6,679 followers · starred May 2020
150 followers · starred Jul 2026
377 followers · starred Feb 2017