-
Notifications
You must be signed in to change notification settings - Fork 10
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
- Protocol Header
- Command Header
- Commands:
- Acknowledge
- Connect
- Verify Connect
- Disconnect
- Ping
- Send Reliable
- Send Unreliable
- Send Fragment
- Send Unsequenced
- Bandwidth Limit
- Throttle Configure
| 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
| 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
Description: Acknowledge a received segment
| 0 | 1 | 2 | 3 |
------------------------------------------------------------
0 | Received Seq Number | Received 'Sent Time' |
------------------------------------------------------------
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
| 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 |
------------------------------------------------------------
| 0 | 1 | 2 | 3 |
------------------------------------------------------------
0 | Data |
------------------------------------------------------------
Description: Check if the peer is still alive
[empty]
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
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
| 0 | 1 | 2 | 3 |
------------------------------------------------------------
0 | Start Sequence Number | Data Length |
------------------------------------------------------------
4 | Fragment Count |
------------------------------------------------------------
8 | Fragment Number |
------------------------------------------------------------
12 | Total Length |
------------------------------------------------------------
16 | Fragment Offset |
------------------------------------------------------------
Description: Send a packet out-of-band
| 0 | 1 | 2 | 3 |
------------------------------------------------------------
0 | Unsequenced Group | Data Length |
------------------------------------------------------------
Followed by [data length] bytes of data
Description: Limit the bandwidth of the connection. Not implemented.
| 0 | 1 | 2 | 3 |
------------------------------------------------------------
0 | Incoming Bandwidth |
------------------------------------------------------------
4 | Outgoing Bandwidth |
------------------------------------------------------------
| 0 | 1 | 2 | 3 |
------------------------------------------------------------
0 | Packet Throttle Interval |
------------------------------------------------------------
4 | Packet Throttle Acceleration |
------------------------------------------------------------
8 | Packet Throttle Deceleration |
------------------------------------------------------------