Appearance
Protocol Hash Check
This page describes how to prevent clients from connecting to the server when their serialization protocols differ.
Appearance
This page describes how to prevent clients from connecting to the server when their serialization protocols differ.
When a client connects with the same logic version as the server's latest supported logic version, the client and server are expected to share an identical serialization protocol. If their Protocol Hashes differ, the shared data structures (actions, models, or messages) were changed on only one side without bumping the logic version. Such a mismatch leads to checksum mismatches or deserialization failures that are hard to diagnose.
This most commonly happens in local development using Unity Editor. Changing the source code affecting the protocol causes the client to be automatically rebuilt, but the running local server is not.
Automatic Local Server Rebuild
To automatically rebuild and restart the server when shared code is changed, use the watch-flag when starting the server:
metaplay dev server --watchThe Protocol Hash Check prevents the possible incompatibility by rejecting connections if the hash of the client and the server differ. In this case, the client will report a MetaplayClientConnectionErrors.ProtocolHashMismatch error when attempting to connect.
In production, the intended solution for incompatible wire protocol is to use Logic Versions. The Protocol Hash Check is only intended to prevent issues stemming from incompatible protocol versions during local development.
The check is controlled with the ClientConnection.ProtocolHashMismatchIsError runtime option.
ClientConnection:
ProtocolHashMismatchIsError: true # Require protocol hash to match
# ProtocolHashMismatchIsError: false # Tolerate protocol mismatchThe Protocol Hash Check defaults to enabled on local environments and disabled elsewhere. Local development is where rebuilding of only client or server is most common. In the production environments, consider using Logic Versions instead.