Jump to content
  • Advertisement
Sign in to follow this  
Kison

Networking- Getting Started

This topic is 5413 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

Hey all, I'm working on a pretty simple game at the moment, one like the old Bomberman in fact(Just Standard Windows Programming, not OpenGL or DirectX yet). I have most of it done on the offline version, but I've been working on getting this over the net so other's can link together and play. I'm pretty sure I understand how most of this is suppose to work. The client sends a request to the server when it needs something. For example, the client is ready to print the screen, so it sends a request to the server for the data required for the next print, and the server will then send the data once it receives the request. Client sends: "REQUEST_PRINT" Server sends: <Tile structures> One of the problems I'm struggling with, though, is how to let the program know to not print until it's received ALL of the data it will need to print. My solution was that I send a character like '@' over to the client to let it know that all of the data it will need to print has been sent, and I made a bool value that changed to true once it received that character. If that bool is true it will print. But for some reason I don't think this is right. I have my program sitting in a loop like this: while(!Serv->Receive()); Which will do basically nothing until it gets everything it needs. So here's my question. What is the standard protocol for a problem like this? The problem being having the CLIENT not print up the screen until it has all of the data it needs. Sometimes I will start my program and the text that is outputted will flicker, which means it is still printing when it hasn't received all it needs. I'm pretty sure there's more I'll need to know sooner or later, but I'll hold off until I stumble onto more problems :) Thanks.

Share this post


Link to post
Share on other sites
Advertisement
If you need to send the entire frame, then the standard protocol is to figure out all the data for the frame on the server, then send a length to the client, followed by the data. The client will read a length, and then will read that many bytes; then it knows it's done.

However, most games don't send the entire map state every frame. Instead, the server sends references to the map and all entities on the map, and some data (such as position of each entity) on start-up; then it only sends changes as they happen (i e, new position for entity X, or new velocity for entity Y). Exactly how this happens varies wildly depending on the game and the requirements.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
So what I should do is re-design.

I guess what I should do is when the game starts, have the server send the data for the entire map over to the client, and each time it needs to re-draw, have it send the data for the CHANGES only.

This would then fix the problem of having to wait for input to re-draw because the client would have all of the data it needed to re-draw an old picture even if all of the input wasn't ready yet.

So in this case, would my client need to make a request for the map changes before it draws, or does the server just send it over whenever the changes occur?

Thanks guys, starting to make more sense. ;)

Share this post


Link to post
Share on other sites
That last poster was me.

I guess another question would be what exactly do you mean by sending only when changes occur? If you mean that someone moves to the right by 4 spaces, how would the server determine how much of a change that is? The server doesn't really know what the client has in it's data, so for every change on the map, do you just make some sort of linked list with each little change, then loop through the changes and send it out all at once?

Sorry for the stupid questions, heheh.

Share this post


Link to post
Share on other sites
Each client sends its changes to the server. The server can just keep a list of all the changes it's received, and from whom, and forward the changes to all other players.

You'll get into interesting cases where both client A and client B think that they came first to the power pill (or whatever), though, which is where having a server that can determine these things authoritatively is really nice.

Ideally, you design your initial game data for networking from the beginning, though -- it sounds like you started with a non-networked game, and you are now trying to shoe-horn networking into it. That's seldom the most optimal stragegy, I'm afraid.

Share this post


Link to post
Share on other sites
Well, I started over. I had this game worked out for the most part on its offline version and just made two seperate programs(Client and Server) and started them from scratch and am trying to add in pieces bits by bits. Networking is harder than I expected it to be though. ;)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!