Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. public static void RunClient(string machineName, string serverName)  
  2.         {
  3.             // Create a TCP/IP client socket.
  4.             // machineName is the host running the server application.
  5.             TcpClient client = new TcpClient(machineName,443);
  6.             Console.WriteLine("Client connected.");
  7.             // Create an SSL stream that will close the client's stream.
  8.             SslStream sslStream = new SslStream(
  9.                 client.GetStream(),
  10.                 false,
  11.                 new RemoteCertificateValidationCallback (ValidateServerCertificate),
  12.                 null
  13.                 );
  14.             // The server name must match the name on the server certificate.
  15.             try
  16.             {
  17.                 sslStream.AuthenticateAsClient(serverName);
  18.             }
  19.             catch (AuthenticationException e)
  20.             {
  21.                 Console.WriteLine("Exception: {0}", e.Message);
  22.                 if (e.InnerException != null)
  23.                 {
  24.                     Console.WriteLine("Inner exception: {0}", e.InnerException.Message);
  25.                 }
  26.                 Console.WriteLine ("Authentication failed - closing the connection.");
  27.                 client.Close();
  28.                 return;
  29.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement