Jump to content
  • Advertisement
Sign in to follow this  
ValdasKalvaitis

Send whole packet instead of single bytes?

This topic is 2686 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I want to create yet another mmo, which is going to be real-time strategy. I will be using Java as server and client language, as it can run on win, mac, linux and others.

Now, to the main question. How do I store packets, then send them all instead sending piece by piece, which may cause trouble if some packets arrive late or don't reach destination point at all? And, if I send more than one query, how do I process it all after receiving data?

At the moment I'm doing something like this, but it isn't working really well.

Server:
for (Player p : players) {
p.write((byte)0); // opcode
p.write((byte)players.size()); // length
for (Player p2 : players) {
p.write(p2.x);
p.write(p2.y);
}
}


And client:
while (true)
if (in.ready()) {
int x = in.read();
if (x == 0) { // 0 opcode, means player updating
Client.play.clear();
int amt = in.read();
for (int i=0; i<amt; i++) {
int xx = in.read();
int yy = in.read();
Client.play.add(new int[] {xx, yy});
}
}



Even this small code causes trouble, because for some reasons sometimes xx and yy isn't read properly and become random numbers.

As you may see, I am very new to networking, so please, could you tell me how should I do this properly? Also, I would like not to use a high-level library of some sort, because I want to understand how everything works.

Share this post


Link to post
Share on other sites
Advertisement
[color="#1C2837"]could you tell me how should I do this properly?[/quote]
[color="#1C2837"]
[color="#1C2837"]Begin by reading the material linked to in the forum FAQ.
[color="#1C2837"]
[color="#1C2837"]Not only are your questions answered by the FAQ links, but also you have common errors and problems that are addressed in the FAQ.
[color="#1C2837"]
[color="#1C2837"]Follow the FAQ, and the FAQ shall set you free. Or something like that.

Share this post


Link to post
Share on other sites

Now, to the main question. How do I store packets, then send them all instead sending piece by piece, which may cause trouble if some packets arrive late or don't reach destination point at all? And, if I send more than one query, how do I process it all after receiving data?


In a real-time game, there are no "queries." A technical design that is waiting on someone else at any point (except perhaps initial level sync, if everyone starts the game at the same time) *will* kill your game.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!