Sign in to follow this  
ValdasKalvaitis

Send whole packet instead of single bytes?

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:
[code]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);
}
}[/code]

And client:
[code]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});
}
}[/code]


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
frob    44975
[quote][color="#1C2837"][size="2"]could you tell me how should I do this properly?[/quote][/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]Begin by reading the material linked to in the forum FAQ. [/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]Not only are your questions answered by the FAQ links, but also you have common errors and problems that are addressed in the FAQ.[/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]Follow the FAQ, and the FAQ shall set you free. Or something like that.[/size][/color]

Share this post


Link to post
Share on other sites
hplus0603    11356
[quote name='Valdas' timestamp='1302504087' post='4796961']
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?
[/quote]

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this