Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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 1647 times)
0 Members and 1 Guest are viewing this topic.
Offline appel

JGO Wizard


Medals: 49
Projects: 5


I always win!


« Posted 2006-01-08 18: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 @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Aramaz

Junior Member




Java Games Rock!


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

what kind of game is it for?

Play XSW: www.xsw.se
Offline appel

JGO Wizard


Medals: 49
Projects: 5


I always win!


« Reply #2 - Posted 2006-01-08 19: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 @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Aramaz

Junior Member




Java Games Rock!


« Reply #3 - Posted 2006-01-09 11: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).

http://www.bookofhook.com/Article/GameDevelopment/TheQuake3NetworkingModel.html

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: www.xsw.se
Offline tom
« Reply #4 - Posted 2006-01-09 14: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:
1  
2  
3  
send input to server
render  // rendering while waiting for the server will reduce lag.
read state from server


...and the server:
1  
2  
3  
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 Member




Friendly fire isn't friendly!


« Reply #5 - Posted 2006-01-18 17: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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (18 views)
2014-04-15 18:08:23

BurntPizza (15 views)
2014-04-15 03:46:01

UprightPath (28 views)
2014-04-14 17:39:50

UprightPath (13 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (54 views)
2014-04-10 04:04:31

BurntPizza (111 views)
2014-04-08 23:06:04

tom_mai78101 (212 views)
2014-04-05 13:34:39

trollwarrior1 (181 views)
2014-04-04 12:06:45

CJLetsGame (187 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org 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‑gaming.org
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!