Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (603)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (652)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Client/Server UDP  (Read 1977 times)
0 Members and 1 Guest are viewing this topic.
Offline appel

JGO Wizard

Medals: 69
Projects: 4

I always win!

« Posted 2006-01-08 17:48:15 »

I'm designing a game and I'd like to read more about how to keep the logic on the server, and let the client only display the game state.

That is, the client should only report to the server via udp packet what he is doing; that is what keys he's pressing basicly. Server replies by sending the client new coordinates and stuff.

What is the best approach to do this?

Check out the 4K competition @
Check out GAMADU (my own site) @
Offline Aramaz

Junior Devvie

Java Games Rock!

« Reply #1 - Posted 2006-01-08 18:22:04 »

what kind of game is it for?

Play XSW:
Offline appel

JGO Wizard

Medals: 69
Projects: 4

I always win!

« Reply #2 - Posted 2006-01-08 18:58:04 »

Well, should that really matter?

It's basicly a fighter game, each player controls a unit on the screen and that unit can move around and shoot at other players. Very simple.

There is a standalone server, that I will run, and the clients connect to it. So, the clients basicly need to notify the server what they're doing, and the server needs to keep the clients informed of all changes in the game world.

I know how to send the packets to the server, and let the server reply. But that's only with my prototype, where only a single client is connected. I need to know how to make the server handle multiple clients.

Note: this is for my 4k game :] so, libraries or any complex structures are not possible.

edit: I'm not look for someone to do things for me, all I'm looking for are references; tutorials, books, any texts explaining this. Just looking for pointers.

Check out the 4K competition @
Check out GAMADU (my own site) @
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Aramaz

Junior Devvie

Java Games Rock!

« Reply #3 - Posted 2006-01-09 10:58:56 »

It matters because if it's a slow game, ie turnbased, then it's very simple and you can just send the whole state, and the clients doesn't need to compute transitions between states. In an action game, the client will have to interpolate so you get smooth action even though game state data doesn't arrive every frame...

It's a pretty simple scenario. What I do is that on the server I make a unique key from each connected client's remote address (ip & port). This key is put in a player class, that handles all interaction between the server and the player. The player classes are all put in a tree map, and when a packet arrives at the server the key is put together and the correct player is picked from the TreeMap. The incoming packet (in a ByteBuffer) is sent to the player and parsed. Put all keypresses that arrive in a queue or something, then in your game logic loop process each keypress to compute the new state.

Then send the new state to each player... this is a link describing how they update the state in quake 3. Found it interesting and useful, I do something similar. (Send dx from the last state successfully acked).

If there are just a small number of entities you'll be ok with sending the whole game state every snapshot (positions, velocity, what they're doing)..

For actions requiring time to perform I'd send the starting time of the action, then the client can compute the following frames based on the starting time. (you don't have time to send what actual animation frame is showing, every frame if you're using a decent frame rate).

Play XSW:
Offline tom
« Reply #4 - Posted 2006-01-09 13:52:53 »

Use TCP instead of UDP. It's less code and you don't have to worry about lost packets and getting data in and out of buffers/arrays.

The easiest way to implement this is to use a simple lock step. The client would do the following:
send input to server
render  // rendering while waiting for the server will reduce lag.
read state from server

...and the server:
read input data from all clients
update state
send state to all clients

This is the way doom did it and will work fine on a lan. It will not work that well on the net since the game will run at speed of the slowest connection.

You can smooth things out by letting the client interpolate between the 2 previous states. But you'll need to run at fixed rate and it's more comlex. The animation will still pause if the slowest connection can't keep up.

Offline Herkules

Senior Devvie

Friendly fire isn't friendly!

« Reply #5 - Posted 2006-01-18 16:53:59 »

Type of game *has* to be considered! For an online flightsim like mine your approach definately is not an option.

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

SHC (17 views)
2015-08-01 03:58:20

Jesse (17 views)
2015-07-29 04:35:27

Riven (38 views)
2015-07-27 16:38:00

Riven (20 views)
2015-07-27 15:35:20

Riven (22 views)
2015-07-27 12:26:13

Riven (13 views)
2015-07-27 12:23:39

BurntPizza (32 views)
2015-07-25 00:14:37

BurntPizza (44 views)
2015-07-24 22:06:39

BurntPizza (25 views)
2015-07-24 06:06:53

NoxInc (33 views)
2015-07-22 22:16:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!