Answer the question
In order to leave comments, you need to log in
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();
}
}
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);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question