public static void RunClient(string machineName, string serverName) { TcpClient tcpClient = new TcpClient(machineName, 443); Console.WriteLine("Client connected."); SslStream sslStream = new SslStream((Stream)tcpClient.GetStream(), false, new RemoteCertificateValidationCallback(SslTcpClient.ValidateServerCertificate), (LocalCertificateSelectionCallback)null); try { sslStream.AuthenticateAsClient(serverName); } catch (AuthenticationException ex) { ProjectData.SetProjectError((Exception)ex); AuthenticationException authenticationException = ex; Console.WriteLine("Exception: {0}", (object)authenticationException.Message); if (authenticationException.InnerException != null) { Console.WriteLine("Inner exception: {0}", (object)authenticationException.InnerException.Message); } Console.WriteLine("Authentication failed - closing the connection."); tcpClient.Close(); ProjectData.ClearProjectError(); return; } byte[] bytes = Encoding.UTF8.GetBytes("Hello from the client.<EOF>"); sslStream.Write(bytes); sslStream.Flush(); Console.WriteLine("Server says: {0}", (object)SslTcpClient.ReadMessage(sslStream)); tcpClient.Close(); Console.WriteLine("Client closed."); }
public static int Main(string[] args) { if (args == null || args.Length < 1) { SslTcpClient.DisplayUsage(); } string machineName = args[0]; string serverName = args.Length >= 2 ? args[1] : machineName; SslTcpClient.RunClient(machineName, serverName); return(0); }