3
\$\begingroup\$

I'm currently working on an online Java game.I am not an experienced game programmer, having only worked with web applications, so far. Currently, I am building the messaging system between the client and the server, and I came across a big "what if".

Currently, the messaging system uses a custom solution and Java NIO with sockets, but it got me wondering: what if it fails? What if I have to change it all to some other system?

I decided that I should abstract the network layer of my engine, and if someday I need to change it, I'll swap the adapter. Then came two more problems; how would I abstract a network layer, and of course, is it worth the trouble? Will it be a waste of time?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

Sockets are going to be around for a long, long time, so I wouldn't worry about that. If it is already working for you, that's even better!

For an interesting messaging layer, check out ZeroMQ.

In general, if you construct your game to have a general sort of event-based flow (i.e.,"Client 2 fire", "Client 1 die", "Sound explosion (2,3,1)", etc.) and use that for all interactions, you then reduce your problem to routing streams of events and handling them.

Your networking issue then becomes one mainly of serializing these events to a communications channel (for example, over sockets), and then deserializing these events to an event stream on the client/server. If you make that abstraction, then any change to the networking mechanism (sockets to modems to semaphores to whatever) means that you only will have to rewrite that serialization/deserialization/channel management code.

Hope that helps!

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .