Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Commit ac58d77

Browse files
committed
add heartbeat request event
1 parent 1259584 commit ac58d77

File tree

1 file changed

+35
-5
lines changed
  • docs/Protocol Specifications

1 file changed

+35
-5
lines changed

docs/Protocol Specifications/core.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ weight: 0
3737
- [3.2.3.6 "Resume" event and "resumed" event](#3236-resume-event-and-resumed-event)
3838
- [3.2.3.7 Server certificate change event](#3237-server-certificate-change-event)
3939
- [3.2.3.8 Heartbeat and heartbeat ACK events](#3238-heartbeat-and-heartbeat-ack-events)
40+
- [3.2.3.9 Heartbeat request](#3239-heartbeat-request)
4041
- [3.2.4 Establishing a connection](#324-establishing-a-connection)
4142
- [3.2.5 Closing a connection](#325-closing-a-connection)
4243
- [3.2.6 Guaranteed delivery of gateway messages through package acknowledgement](#326-guaranteed-delivery-of-gateway-messages-through-package-acknowledgement)
@@ -269,7 +270,7 @@ The following opcodes are defined by the `core` namespace:
269270

270271
| Opcode | Name | Action | Description |
271272
| ------ | ------------------------------ | ------------------ | ---------------------------------------------------------------------------------------------------------------- |
272-
| `0` | Heartbeat | Actor Send/Receive | Keep alive for the WebSocket session. |
273+
| `0` | Heartbeat | Actor Send | Keep alive for the WebSocket session. |
273274
| `1` | Hello | Actor Receive | Received upon establishing a connection. |
274275
| `2` | Identify | Actor Send | Identify to the server. |
275276
| `3` | New Session | Actor Receive | Received by all sessions except the new one. |
@@ -280,6 +281,7 @@ The following opcodes are defined by the `core` namespace:
280281
| `8` | Service Channel | Actor Send/Receive | Open or close a service channel. |
281282
| `9` | Service Channel ACK | Actor Receive | Acknowledgement of a service channel event. |
282283
| `10` | Resumed | Actor Receive | Replayed events. |
284+
| `11` | Heartbeat Request | Actor Receive | The server requests a heartbeat from the client ASAP. |
283285

284286
##### 3.2.1.3 Sequence numbers `s`
285287

@@ -299,10 +301,12 @@ form an application-layer packet acknowledgement mechanism. The client continuou
299301
event to the server with the interval specified in the ["Hello" event payload](#3231-hello-event).
300302
The server must acknowledge the heartbeat event by sending a heartbeat ACK event back to the client.
301303

302-
Servers must account for the time it takes for the client to send the heartbeat event. Before closing
303-
a connection due to a missed heartbeat, the server should request a heartbeat event from the client
304-
by sending a heartbeat event to the client. If the client is not responding within a reasonable
305-
time frame, the server should close the gateway connection with an appropriate [close code](#325-closing-a-connection).
304+
Servers must account for the time it takes for the client to send the heartbeat event.
305+
306+
Before closing a connection due to a missed heartbeat, the server should request a heartbeat event
307+
from the client by sending a heartbeat request event to the client. If the client is not responding within
308+
a reasonable time frame, the server should close the gateway connection with an appropriate
309+
[close code](#325-closing-a-connection).
306310

307311
The structure of the heartbeat and heartbeat ACK events are described in [section 3.2.3.8](#3238-heartbeat-and-heartbeat-ack-events).
308312

@@ -683,6 +687,32 @@ As such, the field `d` in a heartbeat ack may be empty, but never not present. T
683687
an array of other gateway events. Heartbeat ACK payloads must not be present in this array, making recursion
684688
impossible.
685689

690+
##### 3.2.3.9 Heartbeat request
691+
692+
The server may manually request a heartbeat from a client at any time.
693+
A heartbeat is usually manually requested, if the server has not received a heartbeat from the client
694+
in due time. Clients should keep their "heartbeat timer" running as is after sending a heartbeat following
695+
a heartbeat request.
696+
697+
!!! info
698+
699+
If the client heartbeat timer states that the next heartbeat in a heartbeat interval of 45 seconds
700+
is due in 8 seconds, the timer should still "read" ~8 seconds after a manual heartbeat request
701+
has been fulfilled. Of course, the client should not send the same heartbeat twice.
702+
703+
Heartbeat request events do not carry any data in their `d` payload.
704+
705+
!!! example "Example heartbeat request event payload"
706+
707+
```json
708+
{
709+
"n": "core",
710+
"op": 7,
711+
"d": {},
712+
"s": 1
713+
}
714+
```
715+
686716
#### 3.2.4 Establishing a connection
687717

688718
TODO

0 commit comments

Comments
 (0)