Understanding network code

Started by
1 comment, last by hplus0603 9 years, 11 months ago

I am trying to understand how a server communicates properly with the clients

Player1 Moves which means his new position needs to be updated on the server

Player2 Moves which means his new position needs to be updated on the server

Player1 screen needs to see the updated position of Player 2

Player2 screen needs to see the updated positon of player 1

My question is how do you make the server only send the clients that need updating and not its self,this is going to be become more trickyer with more clients so i am unsure how to implement updating of the clients screen correctly,what i mean is like

5 Players on the server

Player1 Moves

Player2 to 5 needs to see Player1 updated position

Player3 Moves

Player1,2,4,5 needs to see Players3 updated position

see what i am getting at?

:)
Advertisement

Basic idea:

Player 1 moves, and sends its own updated position to server.

Server sends Player 1's updated position to Players 2,3,4 and 5.

And then there is a whole world of magic like

"lag compensation", "cheating prevention", "bandwidth management", "dynamic game entry/leave", etc...

The typical way this is solved:

1) Set a fixed send rate -- say, 10 times a second, or 20 times a second

2) Each time the send time comes up, iterate through all the players

3) For each player, get the data they need to receive, and send it in one packet

Note that, on a bigger map, you may not want to send all the data for all the players; you may want to do interest management and only send data about players that can be seen, for example.

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement