Hey GD!
I was thinking about implementing an online server-client game and here is what I came up with:
1. The game is driven by events (if a player gets shot, an event is generated, etc).
2. The event is converted to some sort of format and sent to the server.
3. The server sends it back to all clients but the original sender.
4. The clients convert it back and make the necessary changes in game logic.
Does that sound like it could work? I haven't been able to think about a better solution myself.
Now the real question is (if my solution makes sense), what format should I use to send my event classes through UDP sockets? Should I just convert their data to strings? Are there popular solutions to this?
If your new to networking I really think just using TCP would just be easier.
TCP is stream based, you don't have to worry about packing multiple messages into a network segment/packet. You also wont have to deal with issues like packet loss.
TCP really is not that slow like people say it is, it can become crippled on unstable connections otherwise it works quite well. Last I heard World of Warcraft uses TCP still and I have 250 millisecond of lag from australia -> america which is pretty average. Otherwise, if you can handle the required UDP work then I'm wrong use UDP all you want :D.
(following text will probably work more ideally in a TCP environment, with UDP you'd probably have to do what hplus said, 2nd post).
Also instead of converting data to strings (I used to do this when I first started networking) instead just send message types as bytes, no conversion needed... A player moved? Ok that could be byte 0, a player jumped? that could be byte 1. Prefixing messages with these bytes I think would be a better idea. Each message type could also have its own structure, say, for message 0 (a player moved)... It could look something like this:
{message byte (0)} {player who moved} {direction in which they moved} {current local position} {current local velocity} etc.. etc...
This is a example of a client->server message.
Once the server receives this it can then process it in a specific way (depending on the message type). For example in this case the player moved (message 0) so it can compare the current position of the player to the one in the message to see if the player is cheating (x/y/z has changed too much relative to current stored x/y/z). If the bounds are met then the player position is changed etc. etc.. server sends out a different type of server->client message to all the players but the source player indicating that the player moved.
Doing this means you probably wont need to serialize, saving loads of bandwidth.
I hope that helps, I'm still sort of new to networking myself.