0
\$\begingroup\$

I have developed a 2D RPG MMO client / server. The server is developed in C# with asynchronous sockets. It is a pretty simplet implementation. The server gets the client's input / coordinates and broadcasts it to the other players. It is a very alpha stadium so that I only want to test performance to know if this way to go is good.

Now I am living in Germany, I have a static public IP (accessible via the internet) and deployed my game server on a Raspberry Pi 3 (it runs in the command line with C# / Mono). The only database access (write / read) is currently made, when a client connects or disconnects (store / load coordinates).

I made a speed test right now and have the following result: Download Speed: 100840 kbit/s Upload Speed: 8973 kbit/s The Raspberry Pi is connected on a router (Fritz Box) via LAN and the port is set to bridge mode (because of the public static IP).

Everything runs fine, but I tested it with ony two clients and when one client begins to move, the second client "sees" it maybe 1 second later. The movement is "lag free". But of course, it takes a lot of time until the signal arrives to the other clients.

My question now is, will I have the same issues later, when I rent a server? I really hope that this is what I should expect, when I run my server in my home network. Maybe this question is pretty difficult to answer, because I give you no source code of the server here, but as I said, when the clients get the signal, it is "lag free". The only thing I have is kind of a "delay".

Thanks in advice.

\$\endgroup\$
  • \$\begingroup\$ You might want to implement a simple ping protocol in your netcode so you can properly measure latency. That will help you a lot in diagnosing such problems. \$\endgroup\$ – Philipp Aug 7 '17 at 12:55
1
\$\begingroup\$

A latency of 1000ms on a home LAN is not normal. It should usually be in the tenths of milliseconds with Wifi and even lower with Ethernet. But there might still be a problem with your home LAN. You should test the latency to the Raspberry Pi with the ping command line program while your server isn't running and check the latency time. You can't expect a better latency than that for your game.

When the latency on your home LAN is allright, the problem might also be that the small little Raspberry is simply not powerful enough to run your server. You might want to run it on proper hardware. If you don't want to buy a second computer, you can create a virtual machine on your development computer with a software like VirtualBox to run your server.

When you are playing on a VM running on localhost, the latency times should be pretty much unnoticeable. When the problem persists under these conditions, then the problem is definitely in your code. But without looking at it, it is impossible to guess where the problem might be. There is a million things which could be wrong. Not just on the server but also on the client-side.

\$\endgroup\$
-3
\$\begingroup\$

I think your accept-lag-delay problem is in accepter loop.

Dont Use -> Sleep()

Use -> ManualResetEvent

When you are trying to accept a client with main loop accepter, dont use sleep or like functions. The best way to make this ManualResetEvent

https://msdn.microsoft.com/en-us/library/system.threading.manualresetevent(v=vs.110).aspx

I give you an example ;

ManualResetEvent Waiter = new ManualResetEvent(false);

void Listener()
{
    while (ListenerSocket != null)
    {
        Waiter.Reset();
        try
        {
            ListenerSocket.BeginAccept(new AsyncCallback(AcceptConnectionCallback), null);
        }
        catch (Exception ex)
        {
            Log.WriteError(ex, "void Listener()");
        }
        Waiter.WaitOne();
    }
}

void AcceptConnectionCallback(IAsyncResult iar)
{
    Socket ClientSocket = null;
    Waiter.Set();
    try
    {
        ClientSocket = ListenerSocket.EndAccept(iar);
    }
    catch (Exception ex)
    {
        Log.WriteError(ex, "void AcceptConnectionCallback(IAsyncResult iar) /1");
    }
}

Sleep() function is always a bad choice for CPU Relax in accepter loop. Because it can cause lag and little bit bottleneck. ManualResetEvent is best and optimized way to do this.

\$\endgroup\$
  • 2
    \$\begingroup\$ You are making a lot of guesses about possible causes without having even seen the code of the server in question. That's not very helpful. \$\endgroup\$ – Philipp Aug 7 '17 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.