G
G
gen_dalf2015-02-20 17:20:33
System administration
gen_dalf, 2015-02-20 17:20:33

Very high ping in a client-server application on Windows Server 2012. How to reduce it?

I created a cloud server on Windows Server 2012 R2. When you ping from your computer to this server, the ping is on average 60ms. I wrote a simple client/server application in C#.
Customer:

TcpClient client = new TcpClient();
client.Connect(IPAddress.Parse("адрес"), 10000);
NetworkStream stream = client.GetStream();
BinaryReader reader = new BinaryReader(stream);
BinaryWriter writer = new BinaryWriter(stream);
Stopwatch sw = new Stopwatch();
List<float> pings = new List<float>();
DateTime startTime = DateTime.Now;
Random random = new Random();

while(true)
{
    byte[] packet = Enumerable.Repeat<byte>(100, random.Next(50, 100)).ToArray();
    sw.Start();
    writer.Write(packet.Length);
    writer.Write(packet);
    packet = reader.ReadBytes(reader.ReadInt32());
    sw.Stop();
    pings.Add((float)sw.Elapsed.TotalMilliseconds);
    sw.Reset();
    DateTime now = DateTime.Now;          
    if(now - startTime > TimeSpan.FromSeconds(1))
    {
        startTime = now;
        Console.WriteLine(pings.Average());
        pings.Clear();
    }
}

Server:
TcpListener listener = new TcpListener(IPAddress.Any, 10000);
listener.Start();
TcpClient client = listener.AcceptTcpClient();
NetworkStream stream = client.GetStream();
BinaryReader reader = new BinaryReader(stream);
BinaryWriter writer = new BinaryWriter(stream);

while (true)
{
    byte[] packet = reader.ReadBytes(reader.ReadInt32());
    writer.Write(packet.Length);
    writer.Write(packet);
}

When running the server on Windows Server, and the client at home, I get ping results on average 200ms.
In my opinion, the problem lies in the Windows Server settings. Tell me who knows.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gen_dalf, 2015-02-20
@gen_dalf

Solution found. If anyone is interested, here is the article:
https://support.microsoft.com/kb/214397?wa=wsignin1.0
In this code, the problem is solved as follows:
Both in the client and in the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question