1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
TcpClient = new TcpClient(Serveur,Port);
// Create an SSL stream that will close the client's stream.
sslStream = new SslStream(TcpClient.GetStream(), false, new RemoteCertificateValidationCallback (ValidateServerCertificate), null);
// The server name must match the name on the server certificate.
try
{
sslStream.AuthenticateAsClient(serverCertificateName);
try
{
//envoie des identifiants entrés par le client.
byte[] monWriteBuffer=new byte[2048];
byte[] monWriteBuffer2=new byte[2048];
monWriteBuffer = Encoding.UTF8.GetBytes(this._textBoxLogin.Text.Trim() + "<EOF>");
monWriteBuffer2 = Encoding.UTF8.GetBytes(this._textBoxMdP.Text.Trim() + "<EOF>");
sslStream.Write(monWriteBuffer, 0/*offset*/, monWriteBuffer.Length);
sslStream.Write(monWriteBuffer2, 0/*offset*/, monWriteBuffer2.Length);
sslStream.Flush();
string FileLog = "";
// récupération des données envoyées par le serveur.
FileLog = ReadFiles();
...
}
catch(System.Exception ex)
{
// on informe l'utilisateur d'un éventuel echec de la connexion
MessageBox.Show(ex.Message);
}
}
catch (AuthenticationException e)
{
MessageBox.Show("Exception: " + e.Message);
if (e.InnerException != null)
{
MessageBox.Show("Inner exception: " + e.InnerException.Message);
}
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message);
}
finally {
sslStream.Close();
TcpClient.Close();
} |
Partager