Skip to content

Message Types

4. Message Types

4.1 Overview

M2M Protocol defines seven message types for session management and data exchange.

TypeDirectionPurpose
HELLOClient → ServerInitiate session with capabilities
ACCEPTServer → ClientConfirm session establishment
REJECTServer → ClientDeny session with reason
DATABidirectionalExchange compressed payloads
PINGBidirectionalKeep-alive request
PONGBidirectionalKeep-alive response
CLOSEBidirectionalTerminate session

4.2 Message Envelope

All session messages share a common envelope structure:

{
"type": "<MESSAGE_TYPE>",
"session_id": "<string|null>",
"timestamp": <unix_millis>,
"payload": <type-specific>
}
FieldTypeRequiredDescription
typestringREQUIREDMessage type identifier
session_idstringCONDITIONALSession ID (null for HELLO)
timestampintegerREQUIREDUnix timestamp in milliseconds
payloadobjectREQUIREDType-specific payload

4.3 Control Messages

4.3.1 HELLO

Initiates a session with capability advertisement.

Direction: Client → Server

Payload:

{
"version": "1.0",
"algorithms": ["TOKEN", "BROTLI"],
"security_scanning": true,
"max_payload_size": 10485760,
"supports_streaming": true,
"extensions": {}
}
FieldTypeRequiredDescription
versionstringREQUIREDProtocol version (e.g., “1.0”)
algorithmsarrayREQUIREDSupported compression algorithms
security_scanningbooleanOPTIONALSecurity scanning capability
max_payload_sizeintegerOPTIONALMaximum payload size in bytes
supports_streamingbooleanOPTIONALSSE streaming support
extensionsobjectOPTIONALExtension capabilities

Example:

{
"type": "HELLO",
"session_id": null,
"timestamp": 1705520400000,
"payload": {
"version": "1.0",
"algorithms": ["TOKEN", "BROTLI"],
"security_scanning": true
}
}

Processing Rules:

  • Server MUST respond with ACCEPT or REJECT within 30 seconds
  • Client MUST NOT send other messages before receiving response
  • Client SHOULD include all supported algorithms

4.3.2 ACCEPT

Confirms session establishment with negotiated capabilities.

Direction: Server → Client

Payload:

{
"version": "1.0",
"algorithms": ["TOKEN"],
"security_scanning": true,
"session_timeout_ms": 300000,
"extensions": {}
}
FieldTypeRequiredDescription
versionstringREQUIREDNegotiated protocol version
algorithmsarrayREQUIREDSupported algorithms (intersection)
security_scanningbooleanREQUIREDSecurity scanning enabled
session_timeout_msintegerREQUIREDSession timeout in milliseconds
extensionsobjectOPTIONALNegotiated extensions

Example:

{
"type": "ACCEPT",
"session_id": "sess_abc123",
"timestamp": 1705520400100,
"payload": {
"version": "1.0",
"algorithms": ["TOKEN"],
"security_scanning": true,
"session_timeout_ms": 300000
}
}

Processing Rules:

  • Server MUST assign unique session_id
  • Server MUST include only mutually supported algorithms
  • Client MUST store session_id for subsequent messages

4.3.3 REJECT

Denies session establishment with reason.

Direction: Server → Client

Payload:

{
"code": "VERSION_MISMATCH",
"message": "Protocol version 2.0 not supported"
}
FieldTypeRequiredDescription
codestringREQUIREDRejection reason code
messagestringOPTIONALHuman-readable explanation

Rejection Codes:

CodeDescription
VERSION_MISMATCHUnsupported protocol version
NO_COMMON_ALGORITHMNo mutually supported algorithms
SECURITY_POLICYSecurity policy violation
RATE_LIMITEDRate limit exceeded
SERVER_BUSYServer at capacity
UNKNOWNUnspecified reason

Example:

{
"type": "REJECT",
"session_id": null,
"timestamp": 1705520400100,
"payload": {
"code": "NO_COMMON_ALGORITHM",
"message": "Server requires TOKEN algorithm"
}
}

4.4 Data Messages

4.4.1 DATA

Exchanges compressed payloads.

Direction: Bidirectional

Payload:

{
"algorithm": "TOKEN",
"content": "#T1|{...}",
"original_size": 1024,
"security_status": {
"scanned": true,
"safe": true
}
}
FieldTypeRequiredDescription
algorithmstringREQUIREDCompression algorithm used
contentstringREQUIREDCompressed data (wire format)
original_sizeintegerOPTIONALOriginal size for verification
security_statusobjectOPTIONALSecurity scan results

Security Status:

FieldTypeDescription
scannedbooleanWhether content was scanned
safebooleanWhether content passed scanning
threat_typestringType of threat detected (if any)
confidencenumberConfidence score 0.0-1.0

Example:

{
"type": "DATA",
"session_id": "sess_abc123",
"timestamp": 1705520401000,
"payload": {
"algorithm": "TOKEN",
"content": "#T1|{\"M\":\"4o\",\"m\":[{\"r\":\"u\",\"c\":\"Hello\"}]}",
"original_size": 68,
"security_status": {
"scanned": true,
"safe": true
}
}
}

4.5 Keep-Alive Messages

4.5.1 PING

Requests keep-alive acknowledgment.

Direction: Bidirectional

Payload: Empty object {}

Example:

{
"type": "PING",
"session_id": "sess_abc123",
"timestamp": 1705520500000,
"payload": {}
}

Processing Rules:

  • Receiver MUST respond with PONG within 10 seconds
  • Sender SHOULD send PING every 60 seconds during idle periods
  • Three consecutive missed PONGs SHOULD trigger session closure

4.5.2 PONG

Acknowledges keep-alive request.

Direction: Bidirectional

Payload: Empty object {}

Example:

{
"type": "PONG",
"session_id": "sess_abc123",
"timestamp": 1705520500050,
"payload": {}
}

4.6 Termination Messages

4.6.1 CLOSE

Initiates graceful session termination.

Direction: Bidirectional

Payload:

{
"reason": "CLIENT_SHUTDOWN",
"message": "Application closing"
}
FieldTypeRequiredDescription
reasonstringOPTIONALClosure reason code
messagestringOPTIONALHuman-readable explanation

Closure Reasons:

CodeDescription
CLIENT_SHUTDOWNClient application closing
SERVER_SHUTDOWNServer shutting down
TIMEOUTSession timeout exceeded
ERRORUnrecoverable error
NORMALNormal closure

Example:

{
"type": "CLOSE",
"session_id": "sess_abc123",
"timestamp": 1705520600000,
"payload": {
"reason": "NORMAL"
}
}

Processing Rules:

  • Receiver MUST acknowledge by closing connection
  • Receiver SHOULD NOT send further DATA messages
  • Either endpoint MAY initiate CLOSE

4.7 Message Sequence

4.7.1 Successful Session

Client Server
| |
|---------- HELLO ----------------->|
|<--------- ACCEPT -----------------|
| |
|========== DATA ==================>|
|<========= DATA ===================|
| |
|---------- PING ------------------>|
|<--------- PONG -------------------|
| |
|---------- CLOSE ----------------->|
| |

4.7.2 Rejected Session

Client Server
| |
|---------- HELLO ----------------->|
|<--------- REJECT -----------------|
| |

4.7.3 Stateless Mode

Client Server
| |
|========== DATA (no session) =====>|
|<========= DATA (no session) ======|
| |

In stateless mode, session_id is null and no HELLO/ACCEPT exchange occurs.