I need to write a messaging protocol between client and server for a game application. I need to send messages back and forth such as, Player joined a game, player left game, player performed this action, etc.
I have a ClientMessage class that will construct a udp or tcp message to the client and send as plain text for now. But of course for the client to understand, there should be a simple protocol for each type of message (the aforementioned examples).
I am just not sure where to start as I've never had to. My only idea is
// Player actions
private int playerJoinGame = 100;
private int playerLeaveGame = 101;
// Game events
private int gameStart = 200;
private int gameEnd = 201;
Then a message would look like
public PlayerJoinGame(string playerName){
string msg = playerJoinGame + ',' + playerName;
SendClientMessage(msg);
}
Does this design pattern make sense? Is the only way to manage this, that is writing the responding end (client), to just be diligent and make sure when you update the server code, you update the cilent? (if event IDs change).
Thanks.