Non-Java game communication (with jme)

Hi everyone,

something I’d like to do is create a game that can work cross-platform. This means I need some sort of custom higher level game networking protocol (guaranteed fun). I’m thinking about using protobuf, because I really don’t want to even think about doing this in python or javascript myself, so I guess I’m doing it that way.

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 messages.
  • 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.

P.S.

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.

UDP is fire and forget, for example the server sends to the client - “player is at positionx,y,z”. Who cares if that makes it through, there will be a new message in milliseconds saying that now the player is at position x.y.z.

“SpiderMonkey uses custom serializers” - then you can write you serializer using protobuf and keep using spidermonkey. Or the library Paul wrote (GitHub - Simsilica/SimEthereal: A high performance library for real-time networked object synching.). I recommend using one or the other rather than writing your own netcode because that is a black hole where all your time will disappear :slight_smile:

Clarification: SimEthereal is built on spider monkey… it uses it to send the UDP messages.

It builds a semi-reliable protocol on UDP that is optimized for syncing object state. In other words, it is ok with forgetting some stuff but also maintains a reliable baseline from which to calculate deltas. It’s a bit complicated.

Libraries in other languages could be written to deal with spider monkey’s protocol. It would be significant work, I guess… but no more than the other approaches mentioned.

This isn’t really cross-platform… this is cross-language. The obstacles will be numerous and extend beyond just the low level network protocol you pick. This is probably a two year task for one person to get right… if they already have extensive experience.