0
我正在编写套接字服务器程序。它将监听特定的IP和端口。一旦数据进入,它就会处理数据并将其存储在数据库中。 我希望我的程序能够收听24 * 7数据是否进入。如果谈到然后对其进行处理,否则等到有新客户加入异步套接字服务器中的OutOfMemoryException
下面是示例代码
static async Task AcceptClientsAsync(TcpListener listener, CancellationToken ct)
{
try
{
var clientCounter = 0;
while (!ct.IsCancellationRequested)
{
TcpClient client = await listener.AcceptTcpClientAsync().ConfigureAwait(true);
clientCounter++;
EchoAsync(client, clientCounter, ct);
}
}
catch (Exception e)
{
NewLog.WriteErrorLogToBuffer("exception in AcceptClientsAsync " + e.InnerException, false);
}
}
它工作正常,但一段时间后,我得到了内存异常。有什么办法可以解决这个问题吗?