Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  
  Networking protocol  (Read 1796 times)
0 Members and 1 Guest are viewing this topic.
Offline antoinelechacal

Junior Duke





« Posted 2005-12-19 15:03:17 »

Hi.

I'm looking for a good synchronising method for my MMORPG game, I'm using an Client/Server architecture.
Actually, I don't know how to design my network protocol: how to prevent lags and other timing problems...
What is the best way to synchronize the clients with the server?
If you have any idea, could you describe your solution?

Thanks.


My name is nobody
Offline appel

JGO Wizard


Medals: 51
Projects: 4


I always win!


« Reply #1 - Posted 2006-01-02 03:48:10 »

I have similar questions.

Although my game is not MMORPG, it's a simple fighter game.

I've managed to get simple communications to work, like client sends X-axis coordinate to server, and server echos back those same coordinates.

Forgive me about these stupid questions, but:

For DataOutputStream there is the method, writeInt(int). How do I send X and Y coordinates, and make the server tell the difference? It seems I can only send primitives over, so I need a way for the server to determine what is what. Would I send over a String in some predetermined format? Like: "324,134"   to indicate x,y point?

There are few properties I need to send to the server; X location, Y location, how the unit is rotated (Angle), Health.

Also, so I simply write this information to the dataoutputstream for each gameloop?


edit: sorry for the hijack Smiley topics look similar, and didn't want repost this question.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Jeff

JGO Coder




Got any cats?


« Reply #2 - Posted 2006-01-02 06:11:21 »

I have similar questions.

Although my game is not MMORPG, it's a simple fighter game.

I've managed to get simple communications to work, like client sends X-axis coordinate to server, and server echos back those same coordinates.

Forgive me about these stupid questions, but:

For DataOutputStream there is the method, writeInt(int). How do I send X and Y coordinates, and make the server tell the difference? It seems I can only send primitives over,

While you COULD use ObjectOutputStream and serialization, that in general is the wrong solution.
The right one is just be the order of the data.  if you write X follwoed byY then you are going to read X followed by Y.

Quote
There are few properties I need to send to the server; X location, Y location, how the unit is rotated (Angle), Health.

Okay take a BIIG step back.  And for the moment forget about DataOutputStream.

Network data is generally sent in packets.  Each packet is clump of  bytes in a known organization that you decide when you design the network code.  In the case of a stream protocol like TCP, you "packetize" by writing a header at the front of each packet, this can be as little as a single int telling you the size of the following packet in bytes.  You want to write the packet with a single call to OutputStream.write.  This way it willa rrive together as a sensible packet on the opther end.

This means you want to have your entire packet in a byte array to write().  You do this by wapping a DataOutputStream around a ByteArrayOutputStream.  Write your data in sequence to the DataOutputStream, flush() the stream (critically important) and then get the byte array from the ByteArrayOutputStream.

You send that byte array with a write() call on the outputstream returned from your socket;'s getOutputStream() call.
On the other side you read the size as a byte from the inputstream returned from that socket's getInputStream() call,  youi then create a byte array big enough to gold the packet and read that from the dtream.  That is then generally passed to your higher level logic which will pull it apart by wrapping a ByteArrayInputStream around the byte array and a DataInputStream around thet ByteArrayInputStream.  Then you read the data from that stream in exactly the order you wrote it when sending it.

Quote
Also, so I simply write this information to the dataoutputstream for each gameloop?

Well unless youir game is trivially simplke there is nothing "simple" about this.  It wil lalways depend on how your game is structured, but usually writing a apcket per frame will send way more data then you want to spend your time either sending or receiving.    Networkign isn't sometying you can easily "paste onto" a game at the end.  To be done well it needs to be consdiered as part of your total game design.  If youa re going to be trying to do game play over the inetrnet this ebcoems even more critical as handling network latencies well is going to have to drive the entire design of your game.


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #3 - Posted 2006-01-02 06:16:15 »

A good example of how networking effects the core of your game design can be foudn in this discussion we had with Kev about his neotworking in his RPG.  There is a lot of good stuff to be elarned sifiting through this...

http://www.java-gaming.org/forums/index.php?topic=10516.0

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline appel

JGO Wizard


Medals: 51
Projects: 4


I always win!


« Reply #4 - Posted 2006-01-02 06:24:01 »

Seems like I have some nice amount of reading and training to do .... better get to it.

Thanks for your reply Jeff, was useful.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Herkules

Senior Duke




Friendly fire isn't friendly!


« Reply #5 - Posted 2006-01-18 17:04:29 »

Consider HeadQuarters 'location' subsystem which give you automatic distribution of positional data. Plus some dead-reckoning if you like. The protocol is binary and saves some bandwidth compared to string serialized transmission.

http://www.flyingguns.com

Browse to the SourceForge project and grab the code from cvs.

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.

Longarmx (37 views)
2014-10-17 03:59:02

Norakomi (28 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (27 views)
2014-10-15 16:18:58

TehJavaDev (52 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (42 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (77 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!