У меня был клиент-сервер Tcp, когда между клиентом и сервером была завершена функциональность, я добавил поток SSL для соединения
Клиент:
public void ReceiveMessage()
{
var clientCertificate = new X509Certificate2(ClientCertificateFile, ClientCertificatePassword);
var clientCertificateCollection = new X509CertificateCollection(new X509Certificate[] { clientCertificate });
string ServerCertificateName = "MyServer";
sslStream = new SslStream(this.GetStream(), false, App_CertificateValidation);
sslStream.AuthenticateAsClient(ServerCertificateName, clientCertificateCollection, SslProtocols.Tls12, false);
while (!SLLConnectionSuccess)
{
if (sslStream.IsAuthenticated)
{
SLLConnectionSuccess = true;
break;
}
}
while (!ClosedThreads)
{
byte[] buffer = new byte[1];
int bytes = -1;
try
{
bytes = sslStream.Read(buffer, 0, buffer.Length);
//Actions..
}
catch()
{
}
}
}
Сервер:
public void Process()
{
Stream = client.GetStream();
using (var sslStream = new SslStream(Stream, false, App_CertificateValidation))
{
sslStream.AuthenticateAsServer(serverCertificate, true, SslProtocols.Tls12, false);
sslstream = sslStream;
while (true)
{
byte[] buffer = new byte[1];
try
{
sslStream.Read(buffer, 0, buffer.Length);
//Actions
}
catch(System.IO.IOException e)
{
}
Thread.Sleep(5);
}
}
}
Я не могу решить проблему, когда происходит сбой сервера, и клиент понимает это и разрывает соединение.При работе с TCP я использовал ping, но он здесь не работает.Буду благодарен за любую помощь.