Jump to content
  • Advertisement
Sign in to follow this  
Tokage

A Networking wtf (forgive the n00b)

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

I'm new to network programming, and I'm trying to write a simple multiplayer game right now. It involves little triangles that move around a simple playing field and shoot at each other. I have a simple server and client set up, using WSAEventSelect() to handle the sockets. But I'm having a weird problem: The client and server seem to be able to talk to each other, but only intermittently. I can open the server and two clients, and when I move one of the clients' triangle dealies, it doesn't appear consistently in the other client window. Instead, it seems to be randomly flickering; both clients are displaying the other's triangle at the same time, and whenever it's gone on one it's gone on the other too. I'm having the client send the triangle object over every frame, and keep an array of other shapes from which it picks the ones to draw every frame. Whenever the server gets a position-update packet, it propagates it to all the other active clients, along with a consistent index with which to refer to the object, and whenever a client receives such a packet (along with an index) it updates the triangle at that index in the array. Is there something wrong with this system? Is there a better way to be handling it? I basically made this whole thing up off the top of my head, so I wouldn't be surprised if there was a better way to be doing it. If anyone wants the relevant code I'll be happy to provide it.

Share this post


Link to post
Share on other sites
Advertisement
Is it possible that somewhere in your main loop you are resetting the position of the remote triangle (possibly somewhere outside the screen)? Otherwise it sounds like it should work, although sending a packet every frame will flood any realistic network outside of a LAN. It's hard to say more without some code snippets to work from.

Try printing out frame counter, triangle position, and whether a packet has been recieved, at each frame. That should get you some more info to work with.

Share this post


Link to post
Share on other sites
I would suggest you log the positions you draw the triangles (and other entities) at to a file, with some identifying information. Run the game slowly (say, 10-20 frames per second), and log for 10 seconds. Then go over the code and see if the data jumps around. If so, try putting in conditional breakpoints in the code that break only when the data goes bad, and run again; catch the bug in the process.

Remember: anything that is consistently reproducible can be fixed with persistence and divide-and-conquer methodology.

Share this post


Link to post
Share on other sites
The position isn't the problem: I'm logging the position and it's consistently (0,0). Would it actually help if I simply sent the packet less frequently?

Okay, I'm going to post some code, just to see if anyone can find anything.

I posted it up here so it wouldn't get too ginormous.

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!