Skip to content

Protocol Structure

Boreeas edited this page Oct 17, 2014 · 17 revisions

Note: This is for the 1.3.x version of ENet. 1.2.x version

Table of Contents

Header

   |      0      |      1      |      2      |      3      |
------------------------------------------------------------
 0 |      Peer Id + Flags      |   [optional] Sent Time    |
------------------------------------------------------------

Note for later: In the official implementation, 
there can be an optional uint32 checksum if the host has a checksum
callback

Peer Id + Flags Format:

| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |10 |11 |12 |13 |14 |15 |
-----------------------------------------------------------------
| x | y | z     |                   Peer Id                     |
-----------------------------------------------------------------
x = FLAG_SENT_TIME
y = FLAG_COMPRESSED
z = Session

FLAG_SENT_TIME = if included, Sent Time field is sent, otherwise, header length is 2 bytes


Command Header

   |      0      |      1      |      2      |      3      |
------------------------------------------------------------
   |0|1|         |             |                           | 
 0 |A|U| Command | Channel ID  | Reliable Sequence Number  |
------------------------------------------------------------

A = FLAG_ACKNOWLEDGE - This packet should be acknowledged. 
    Attempts to resend the packet are going to be made until the ack comes in
U = FLAG_UNSEQUENCED
Command = The id of the command being sent. Valid commands are
-  1 = ACKNOWLEDGE
-  2 = CONNECT
-  3 = VERIFY_CONNECT
-  4 = DISCONNECT
-  5 = PING
-  6 = SEND_RELIABLE
-  7 = SEND_UNRELIABLE
-  8 = SEND_FRAGMENT
-  9 = SEND_UNSEQUENCED
- 10 = BANDWIDTH_LIMIT
- 11 = THROTTLE_CONFIGURE
- 12 = SEND_UNRELIABLE_FRAGMENT

1 - ACKNOWLEDGE

Description: Acknowledge a received segment

   |      0      |      1      |      2      |      3      |
------------------------------------------------------------
 0 |    Received Seq Number    |   Received 'Sent Time'    |
------------------------------------------------------------

2 - CONNECT

Description: Initiate a connection to a host

   |      0      |      1      |      2      |      3      |
------------------------------------------------------------
 0 |      Outgoing peer id     |     SIN     |    SOUT     |
------------------------------------------------------------
 4 |                          MTU                          |
------------------------------------------------------------
 8 |                      Window Size                      |
------------------------------------------------------------
12 |                     Channel Count                     |
------------------------------------------------------------
16 |                  Incoming Bandwidth                   |
------------------------------------------------------------
20 |                  Outgoing Bandwidth                   |
------------------------------------------------------------
24 |               Packet Throttle Interval                |
------------------------------------------------------------
28 |             Packet Throttle Acceleration              |
------------------------------------------------------------
32 |             Packet Throttle Deceleration              |
------------------------------------------------------------
36 |                      Connect Id                       |
------------------------------------------------------------
40 |                         Data                          |
------------------------------------------------------------
SIN = Incoming session id
SOUT = Outgoing session id

Incoming/Outgoing Bandwidth: 0 indicates any

3 - VERIFY_CONNECT

   |      0      |      1      |      2      |      3      |
------------------------------------------------------------
 0 |      Outgoing peer id     |     SIN     |    SOUT     |
------------------------------------------------------------
 4 |                          MTU                          |
------------------------------------------------------------
 8 |                      Window Size                      |
------------------------------------------------------------
12 |                     Channel Count                     |
------------------------------------------------------------
16 |                  Incoming Bandwidth                   |
------------------------------------------------------------
20 |                  Outgoing Bandwidth                   |
------------------------------------------------------------
24 |               Packet Throttle Interval                |
------------------------------------------------------------
28 |             Packet Throttle Acceleration              |
------------------------------------------------------------
32 |             Packet Throttle Deceleration              |
------------------------------------------------------------
36 |                      Connect Id                       |
------------------------------------------------------------

4 - DISCONNECT

   |      0      |      1      |      2      |      3      |
------------------------------------------------------------
 0 |                         Data                          |
------------------------------------------------------------

5 - PING

Description: Check if the peer is still alive

[empty]

6 - SEND_RELIABLE

Description: Send a reliable packet. This packet will not be delivered until all packets with lower sequence numbers have been received.

   |      0      |      1      |
--------------------------------
 0 |       Data Length         |
--------------------------------

Followed by [data length] bytes of data

7 - SEND_UNRELIABLE

Description: Send an unreliable packet. All further packets with a lower sequence number will be discarded.

   |      0      |      1      |      2      |      3      |
------------------------------------------------------------
 0 | Unreliable Sequence Number|       Data Length         |
------------------------------------------------------------

Followed by [data length] bytes of data

8 - SEND_FRAGMENT

   |      0      |      1      |      2      |      3      |
------------------------------------------------------------
 0 |   Start Sequence Number   |       Data Length         |
------------------------------------------------------------
 4 |                     Fragment Count                    |
------------------------------------------------------------
 8 |                    Fragment Number                    |
------------------------------------------------------------
12 |                      Total Length                     |
------------------------------------------------------------
16 |                    Fragment Offset                    |
------------------------------------------------------------

9 - SEND_UNSEQUENCED

Description: Send a packet out-of-band

   |      0      |      1      |      2      |      3      |
------------------------------------------------------------
 0 |     Unsequenced Group     |       Data Length         |
------------------------------------------------------------

Followed by [data length] bytes of data

10 - BANDWIDTH_LIMIT

Description: Limit the bandwidth of the connection. Not implemented.

   |      0      |      1      |      2      |      3      |
------------------------------------------------------------
 0 |                  Incoming Bandwidth                   |
------------------------------------------------------------
 4 |                  Outgoing Bandwidth                   |
------------------------------------------------------------

11 - THROTTLE_CONFIGURE

   |      0      |      1      |      2      |      3      |
------------------------------------------------------------
 0 |               Packet Throttle Interval                |
------------------------------------------------------------
 4 |             Packet Throttle Acceleration              |
------------------------------------------------------------
 8 |             Packet Throttle Deceleration              |
------------------------------------------------------------

Clone this wiki locally