Small summary of Protocol Buffers for those who don’t know it:
- you have a file (
.proto) which can compile into different languages.
- that file describes objects, named
- that is basically JSON but the end result is shorter.
- In the Java implementation, I cannot read from a TCP stream directly, I have to split the stream into messages myself.
I was wondering how I use this in jME.
- Do I use SpiderMonkey?
- Do I create my own AppState that handles clients/server?
- How separated do jME and the server have to be (i.e. should I use jME utils and classes in my pure game code?)
Another issue is whether to use UDP or TCP. I believe SimEthereal uses UDP, and it’d make sense to use UDP messages to transport protobuf messages, but doesn’t that mean that I need to check myself if the entire message has been transported? And won’t that give issues with order? I’m not experienced at all with UDP, but isn’t UDP more of a pain in the ass than TCP?
The issue with TCP is, as I said before, that I have to prepare the raw data for protobuf, as protobuf has no idea where a message starts and ends or what the type of the message is (that’s what I concluded from testing). This means that in a TCP stream, I need to include headers that give the total amount of data being transmitted.
The whole process of preparing data for TCP seems less painful than accounting for potential loss of data. Is that really true?
The last thing I wanted to mention; I read somewhere that SpiderMonkey uses custom serializers (not java serialization), which I could rewrite in another language, but that just seems lame. If I write python, I want it to be good python spaghetti, not just a Java clone.
I realized I didn't mention anything about the game itself. The game is probably a small (hex?) grid-based RTS with a 'flat' playing ground (i.e. you might have flying units, but they still have simple 2D coordinates). This means I probably need a lot of communication between server and client. I have not made up my mind for further details of the game.