Reliable + Netcode packet number mental model #139
-
|
Hi, firstly thanks for both Reliable and Netcode! I'm wanting to confirm my mental model of how these libraries enumerate their packet numbers. Consider the simplest exchange of between a client and server. The client sends 1 packet over and requests ACK. Upon reciept, the server sends another packet with ACK (and some other data). Over the connection, two packets have been sent, but each endpoint has only sent one. The log below reports for this entire sequence a single packet number of 0. I think this means that: Is this interpretation correct? If true this is confusing because the final client:0 "processing packet 0" and "acked packet 0" refer to different packets. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
|
In the event the code is useful: p1 := [4]u8{1, 2, 3, 4}
reliable_endpoint_send_packet(client.reliable_endpoint, raw_data(&p1), len(p1))
os_Time_Sleep(0.001)
netcode_server_update(server.server, time) //NOTE(Jesse): Receive p1
payload: [8]u8
packet_byte_count: i32
packet_sequence_number: u64
packet_bytes := netcode_server_receive_packet(server.server, 0, &packet_byte_count, &packet_sequence_number)
reliable_endpoint_receive_packet(server.reliable_endpoint, packet_bytes, packet_byte_count)
netcode_server_free_packet(server.server, packet_bytes)
p2 := [4]u8{1, 2, 3, 4}
reliable_endpoint_send_packet(server.reliable_endpoint, raw_data(&p2), len(p2)) //NOTE(Jesse): First packet sent from server but the "2nd" sent on the connection.
os_Time_Sleep(0.001)
time += delta_time
netcode_client_update(client.client, time)
packet_bytes = netcode_client_receive_packet(client.client, &packet_byte_count, &packet_sequence_number)
reliable_endpoint_receive_packet(client.reliable_endpoint, packet_bytes, packet_byte_count)
netcode_client_free_packet(client.client, packet_bytes) |
Beta Was this translation helpful? Give feedback.
-
|
The sequence numbers are simply incremented with each packet sent. They are 16bit so the library has to do some work to handle wrap around but otherwise there is nothing complicated going on here. |
Beta Was this translation helpful? Give feedback.
-
|
Each endpoint has its own sequence # for sends. sequence n from endpoint 1 has no relationship to sequence n from endpoint 2. |
Beta Was this translation helpful? Give feedback.
Each endpoint has its own sequence # for sends. sequence n from endpoint 1 has no relationship to sequence n from endpoint 2.