Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (808)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (872)
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  
  RTS networking setup - what is best?  (Read 6239 times)
0 Members and 1 Guest are viewing this topic.
Offline xannus

Junior Newbie


« Posted 2009-10-06 17:36:46 »


I previously made an RTS, network playable.
It functioned by having the game divided into frames, each frame basically being the game loop.
Each player/client had to send a datagram containing movement info for that frame to the server, which was relayed to each client.
Is this the reccomended way to do the network aspect... with datagrams?
or is there an input / output stream, preferred way?

JamesHancock<br />
Offline Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

« Reply #1 - Posted 2009-10-06 19:09:37 »

I think people typically send the moves back and forth with Sockets (by moves I mean the keyboard input), often along with timestamps. But that's mostly what I've observed here, because I've only made a couple networked games and they weren't at all sophisticated.

See my work:
OTC Software
Offline princec

« JGO Spiffy Duke »

Medals: 1146
Projects: 3
Exp: 20 years

Eh? Who? What? ... Me?

« Reply #2 - Posted 2009-10-06 19:40:20 »

Probably a combination of UDP and TCP is what you might want, though for something like an RTS I have a feeling UDP won't be so useful as it is in FPS type games.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Hsaka
« Reply #3 - Posted 2009-10-06 21:59:41 »

For the RTS that I made, I found that TCP and Lockstep sync worked well.
Offline xannus

Junior Newbie


« Reply #4 - Posted 2009-10-09 13:04:16 »

Thx, all,

I'd like to go with TCP, then.
Would that mean each player/client has a connection to every other client? relaying out timestamped activity info?
Isnt that a serious burden, or will an array of OutputStreams and a separate array of InputStreams be quite managable? 

So, would my client constuctor take an array of outputstreams and InputStreams, or IPaddresses? Should I choose any port number for my game?

JamesHancock<br />
Offline teletubo
Global Moderator

JGO Wizard

Medals: 76
Projects: 4
Exp: 8 years

« Reply #5 - Posted 2009-10-09 13:17:25 »

Would that mean each player/client has a connection to every other client? relaying out timestamped activity info?

No ! That would be a hell to synchronize everything .
You should either have a centralized server in a dedicated machine, or have one of the players to host a game (but that would lead to a lot of issues for people behind NAT) . Then all players connect to the server .

In both cases, each player send their actions to the server  .  The server then validates it and broadcast to other players .
In short, that's it .

Maybe you should try and create a simple chat application with the same architecture before moving on to your RTS. You'll learn a lot and anyway you'll probably want to reuse the code for an ingame chat .

Offline xannus

Junior Newbie


« Reply #6 - Posted 2009-10-09 15:26:56 »


So, something like this...?

In my main(  I create two instances of ChatClass,
both with localhost addresses...
With an ObjectOutputStream on one connecting to an ObjectInputStream on the other?
And I have both with chat windows ...TextArea, Textfield
There should be no firewall issues with that?

JamesHancock<br />
Offline teletubo
Global Moderator

JGO Wizard

Medals: 76
Projects: 4
Exp: 8 years

« Reply #7 - Posted 2009-10-09 16:17:02 »

I didn't quite understand what you meant, but I think it's not a good idea to implement a "client-server" , if that's what you meant . Some games do it like this, for example Tetrinet .
I think it's better if you write just a server, and then both clients connect to it (even if one of the clients is localhost) . this way you can keep things separated and organized, and you dont need to deliver your server to every client .

The server should wait in a thread for incoming connections, with socketServer.accept() , and as soon as a connection is established, put this connection in a list . Each connection instance in the server will have an input and output stream . When a client sends a message (client output stream -> server input stream) , iterate in this list and send the message to all clients (server output stream -> N client input streams) .

I think that should be enough for you to begin with . Afterwards you have to deal with stuff like connection loss, concurrency, etc , but I wouldnt care about that now .

Good luck

Offline Riven

« JGO Overlord »

Medals: 1371
Projects: 4
Exp: 16 years

Hand over your head.

« Reply #8 - Posted 2009-10-09 16:20:26 »

I'd advise you to start with a line based (text based) protocol. You can dump the stream into a file (or to the console) which makes debuging a breeze.

Later, once you are confident that everything works as you like, you can switch to a binary protocol, but often you don't have to. If you think that this makes it too easy for cheaters, well, they don't seem to have much problems figuring out binary protocols, so why bother with security by obscurity. You can make a text based protocol just as safe as a binary one.

ObjectInputStreams / ObjectOutputStreams can be very surprising, if you haven't read the javadoc top to bottom.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline kevglass

« JGO Spiffy Duke »

Medals: 319
Projects: 25
Exp: 22 years

Coder, Trainee Pixel Artist, Game Reviewer

« Reply #9 - Posted 2009-10-09 17:54:32 »

This is how I did it quite a while ago:

About half way down the technical bit starts. I like lockstep synchronization but I hate the one laggy client lags out everyone. The article talks about loose step approach which doesn't have that problem.


Pages: [1]
  ignore  |  Print  

Riven (845 views)
2019-09-04 15:33:17

hadezbladez (5789 views)
2018-11-16 13:46:03

hadezbladez (2602 views)
2018-11-16 13:41:33

hadezbladez (6205 views)
2018-11-16 13:35:35

hadezbladez (1498 views)
2018-11-16 13:32:03

EgonOlsen (4733 views)
2018-06-10 19:43:48

EgonOlsen (5789 views)
2018-06-10 19:43:44

EgonOlsen (3275 views)
2018-06-10 19:43:20

DesertCoockie (4174 views)
2018-05-13 18:23:11

nelsongames (5500 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08 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!