Newbie, need help on creating Real time network game

If I want to make real time game, such as multiplayer RPG across network, what kind of server client procedure should I use?
I have read the TCP/UDP contrast, but not sure how the achitecture would looks like ? anyone have source code to share or any info ?

There is generally two ways to handle communication.
Central or decentral.

Central would mean,you have a server, everyone sends to it, server computes the game state and sends it to all players. Clients only do a “frontend” job, the server decides who takes damage etc.

Decentral means, everyone sends to everyone and you need a way that all clients make the same state out of it.

Basically the server version is easier to handle. Once the game starts, you determine the fastest client and make him server, for he has the greatest load. Every client does a simulation of the game, like a prediction of what he thinks what will happen. They send their interaction with other players to the server, the server makes it all up, solves conflicts and returns a situation to all clients. The clients make up the difference between the server message and his own prediction, which is usually not existent or too small to be noticed.

The major problem is synchronization. When you get a 300 ms delayed msg like do 10 damage to soldier 13, a lot of other stuff has happened.
Consider the following chain of events. Soldier A and B both have 5 HP health

  1. PC 1, time 12: soldier A does 10 damage to soldier B
  2. PC 2, time 15: soldier B does 10 damage to soldier A (he does not yet know that he is dead)

The server gets msg 1 and msg 2, sees that msg 1 happens first and decides, soldier b dies and does no damage
he sends to both PCs soldier A has still 5 hp, soldier B is dead

Now lets say message 1 takes 200 ms to arrive at the server for network reasons.
The server by then has recieved msg 2 and has decided to do 10 damage to soldier A and thus soldier A dies.
Later the server gets msg 1. Basically, he should kill soldier B and revive Soldier A, this would be “right” in the order of time.
But in gameplay it would be irritating. You might want to decide to let soldier B live and tolerate the error.

When playing RTS over network you might see that damage and death has a delay. I remember playing Starcraft, where enemy units sometimes die 200 to 400 ms after the hit, this is the server delay. You see the hit instantly, but the damage is computed on the server and returned to you.

You might encounter some trouble in handling delayed messages. First, messages will not arrive in order of time, so you must provide a timestamp and order them. But there is a maximal wait time, you cannot wait 1 second because there might be a late message. Youll have to drop messages with a too great delay. You can develop a really complex communication protocol.

The advantage in decentral commonication is, that only two interacting clients need to make up their stuff.
PC 1 would send 10 damage at time 12 to soldier B
PC 2 would send 10 damage at time 15 to soldier A
And then they make up a decision.
PC 1 would reply i do not accept your damage, the soldier B dies first
PC 2 can verify this and accepts it
thus you have a synchronized situation
After conflicts are made up, the tell all other clients the new situation.

Well, this is enough to give you an idea.

-JAW

Your description is quite understandable, but im quit the n00b when it comes to networking gameplay… Im working on a project similar to this. Could anybody show me a way to implement this into an applet based mmo such as runescape?

You might want to look at Apache MINA. I was using java.net and java.nio
before, but I am currently changing my game to use the MINA protocol. MINA
uses NIO as underlaying transport protocol.

You could create some sort of protocol using NIO yourself, but I would
suggest you don’t reinvent the wheel.
-> MINA simplifies message passing (belive me, it’s cool to design your
own protocol, but what you really want is create a game! Not a network
protocol)
->Don’t worry, it’s fast enough to do real-time gaming

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

How many players are you going to support in a agame session? if its a dowzen or less I wouldnt worry about NIO. If its upwards of 50 then yes youll definitely need to deal with NIO at least omn the server.

HOWEVER I suspct youa re putting the cart WAY befor the hrose.

What kind of game experience do you have? Real-time networked games are the hardest type to write well. If your just getting into game progrmming Id suggest starting with something much less ambitious.