The releated code
while(true)
{
List<Socket> accept=new List<Socket>{ClientListener.Server,RequestListener.Server};
Socket.Select(accept,null,null,-1);
foreach(var i in accept)
{
if(i == ClientListener.Server)
{
Task.Run(()=>Authenticate(ClientListener.AcceptTcpClient()));
}
else
....
}
}
private void Authenticate(TcpClient client)
{
SslStream ssl=new SslStream(client.GetStream(),false);
try
{
ssl.AuthenticateAsServer(serverCertificate,false,SslProtocols.Tls,true);
ssl.ReadTimeout = 1000;
ssl.WriteTimeout = 1000;
}catch(Exception e)
{
ssl.Close();
client.Close();
ssl.Dispose();
client.Dispose();
return;
}
}
The code is very basical code,but it has a very wired bug.
Firstly,At the beginning that the server started,everything worked.
After almost one hour,the SslStream.AuthenticateAsServer() throw error: Received an unexpected EOF or 0 bytes from the transport stream
And then,about three times connect the server,the client that is SslStream.AuthenticateAsClent throw error:Received an unexpected EOF or 0 bytes from the transport stream.(Note. before it, the client authenticate is ok)
another strange thing maybe releate it when I first connect the server,the memory will increase but during it,I don't connect it again.