Client/Server source-code somewhere?

Hey,

I’m making a 4K game, and it’s gonna be multiplayer. I need a very simple, effecient and very slim code doing the client/server functionality.
Since I’ve never done any game networking, I’m wondering if it was a good way to start by looking at some existing games doing the same?

My idea is somewhat like this:

A# Joining a game

  1. Client connects to server > Server accepts
  2. Client requests map ID -> Server sends map ID -> Client generates map
  3. Client requests current game state status (list of players and their score, gametime etc.) -> Server sends state

B# When done joining the game, the following is repeated continiously

  1. Client tells server where he is located (x,y) -> Server mediates to all clients
  2. Server sends info on state of all players.
  3. Repeat B#1

C# In case of some events performed by either the client or server.

  1. Server sends end-game-signal to all players after X time -> Client displays scores list for few seconds and Server resets itself and finds a new map ID -> Client can reconnect again, if he does -> Start A#1
  2. Player fires his rocket -> Client sends rocket location to server -> Server sends location of rocket to all clients -> Enemy clients determine if they are hit, if so -> Enemy client subtracts health from himself (or destroys himself if low on health) -> Notify server of change -> Server updates game state info.

Something like that.

:slight_smile: Thank you.

Are you really going to have a seperate server machien or is this more of a game host/joiner type thing?

How many players? If its a small number (a dozen or less) Id write it with the host throwing off a Thred that serves a java,net.ServerSocket and then a thread for each connecting user. Clients Id just create onm thread running a java.net.Socket

This is pretty easy code…

Check out Apache MINA: http://directory.apache.org/subprojects/network/.

All you need. It uses NIO, but you won’t need to deal with all the details getting NIO to work!
I switched from low-level NIO programming to MINA and it works like a dream!!!

Check out the “MINA Examples” - Source code link!

I must use the standard java api, so no third-party libraries, as I said, it’s for the 4k competition.

As easy as like there is tons of available source code demonstrating this functionality? :slight_smile:

For those interested, this article helped me a lot:
http://www.javaworld.com/javaworld/jw-12-1996/jw-12-sockets-p2.html

As easy as nobody tends to bother publishing source. But I have a chapter showing the fundamentals of the parts that tend to confuse newbs the most, such as how to do multicast discovery, in Shawn’s book “Practical Java Game Programming.”