Networking for simple 'action game' in c#

Started by
4 comments, last by ChristianJames 17 years, 5 months ago
So i have made this little 2 player game. See screen shot http://www.onk.dk/temp/game.jpg At first I made the game for running on a single PC but now I would like to make it playable over the internet. I have done simple networking applications before but the none of them have had any real issuses about the network performance. Just been messages sent back and forth, didnt really matter if it took 100ms or 1000ms for the package to arrive. However the situation is a little different when it comes to gaming. So what i did was to move the entire game engine to a central server application whitch calculate the new positions, collision detection etc. The clients are now 'empty' and only have the graphical objects for drawing. The clients repaint the screen every 40 ms so ideally I want to retrieve positions from the server at the same rate. As I said, I dont have that much insigt on the network preformance but for starters lets just keep it to a local area network were we have round trip times of 1 or 2 ms. So update every 40 ms souldn't be a problem. So far all my networking experience have been through simple sockes so I took the oppotunity to play with the .NET remoting (the game is written i c#). However I have tried to with both synchronous, asynchronous and running the 'get coordinates from server' in a seperate thread but the performance is horrible to say the least. So i guess the questions are A) Is it a good idea at all to let the server handle all positioning and just let the clients fetch the coordinate every time they redraw the screen ? B) How is the performance of .Net remoting ? is it suitable for gaming ? I have uploaded the game if u wish to try it out and see how it response. First run the server then the client. Press any key to move the red player (it will be moving to the right) www.onk.dk./temp/game.rar I really dont get why its performing like this, after all on localhost it should run smoothly and is data is only a few set of coordinates(well they are Point objects but still). Thanks in advance.
Advertisement
The server should assume that the clients need the data every 40 ms, so the clients don't need to "fetch" it. The server should "push" (or rather, "stream") the data to the clients. The clients should stream a sequence of input events to the server, in turn.

That's a good start -- where you go from there depends entirely on the goals and mechanics of your game.
enum Bool { True, False, FileNotFound };
Yeah that sounds like a good idea. However, i accidently got a little further. I cleaned the server project and rebuilt it and suddely it was a hole different game. Objects responing as they should. Seems that for some mysterious reason there was something wrong with the 'render speed'. Really strange though cause I swaer, I didnt changed anything in the code, it just suddenly worked after wipeing the build.

But as u said ill changed it so the server pushes the data.
Ok so I have been playing around a bit with the networking for this game of mine.
However i seem to run into some problems.
As described above the theory was for the client to get the coordinates (for all moving objects, which is 3) from the server. But reading up abit on the network performance and i find that ppl recommend that u should aim for a latency of 100 ms which then means that i can update the positions 10 tame a sec. But with such a slow update rate the movements wouldnt be very smooth.
THen i thought about having the clients calculating the positions aswell and then just synchronize the positions with the server every 100ms. But how is this possible for with the other player, cause u would not have any idea of when the opposit players is doing.

How on earth is this problem solved in all the games out there ?
I dont necessarily need to know how its done in WoW, unreal tournament but just for a basic game like this one were I have 3 moving objects, two players thats controled by two clients and a ball thats controled by the server.
Did you try 100 ms update rate? Assuming that you do forward extrapolation of some sort (so the object moves on screen more often than 10 times a second), it'll probably be quite smooth enough.

For more information, check out the Forum FAQ which has some links.
enum Bool { True, False, FileNotFound };
Thanks,
Extrapolation was exactly what I was looking for.

This topic is closed to new replies.

Advertisement