Handshake
The Handshake Process
Before any meaningful communication can take place, a handshake is required between the client and the server. The handshake allows the server to identify the client, provide necessary metadata, and establish a session.
When a client connects, it sends an initial handshake request. The server responds with the assigned client ID and available rooms.
Loading diagram...
Request
{
"messageCode": 4,
"event": "handshake"
}
Response
{
"messageCode": 8,
"header": {
"receiver": "a4710c8e-fbd6-4900-ad88-6a13fe34692f",
"sender": "server"
},
"message": {
"rooms": []
}
}
Understanding the Response
header.receiver: The unique client ID assigned by the server — essential for all future communicationsheader.sender: Always"server"for server-sent packetsmessage.rooms: List of rooms the client can see (empty by default)
Customization
Override OnHandshakeReceived in your AltruistGameSessionPortal to customize the response:
protected override async Task<IResultPacket> OnHandshakeReceived(
HandshakeRequestPacket message, string clientId, IResultPacket result)
{
// Modify the result, add extra metadata, etc.
return result;
}
Note:
Always handle the handshake response correctly on the client side, as it provides the client ID needed for all future communications.
Client Types
// Send after connecting
[MessagePackObject]
public class HandshakeRequest
{
[Key(0)][JsonPropertyName("messageCode")] public uint MessageCode { get; set; } = 7;
[Key(1)][JsonPropertyName("token")] public string Token { get; set; } = "";
}
// Receive from server
[MessagePackObject]
public class HandshakeResponse
{
[Key(0)][JsonPropertyName("messageCode")] public uint MessageCode { get; set; }
[Key(1)][JsonPropertyName("rooms")] public RoomInfo[] Rooms { get; set; } = Array.Empty<RoomInfo>();
}