nterry / AwesomeSockets

A fast, lightweight, and easy to use socket library for C#.
Other
156 stars 35 forks source link

TCP connections data exchange cpu memory leak #16

Closed ghost closed 5 years ago

ghost commented 5 years ago

When I am sending and receiving a lot of bytes, there is a problem with cpu memory, CPU memory is fully stuffed, a usage of CPU memory is rising high. What should I do to escape it?

here is the server:

ServerSocket = AweSock.TcpListen(14804);
ClientSocket = AweSock.TcpAccept(ServerSocket);
started = true;
byte[] file = File.ReadAllBytes(@"C:\Users\link\Desktop\Screenshot_1.png");
while (started)
{
    Buffer outBuf = Buffer.New(file.Length);
    Buffer.ClearBuffer(outBuf);
    Buffer.Add(outBuf, file);
    Buffer.FinalizeBuffer(outBuf);
    int bytesSent = AweSock.SendMessage(ServerSocket, outBuf);
    Console.WriteLine("Sent");
}

here is the client:

Client = AweSock.TcpConnect("127.0.0.1", 14804);
byte[] file = File.ReadAllBytes(@"C:\Users\link\Desktop\Screenshot_1.png");
while (started)
{
    Buffer inBuf = Buffer.New(file.Length);
    Tuple<int, EndPoint> received = AweSock.ReceiveMessage(Client, inBuf);
    Console.WriteLine("Received");
    frames++;
}

endless loop may increase the cpu memory usage, but I need it