public void Start()
{
// create a new ManualResetEvent. This will be used to make the main application
// thread wait until the full server reply has been received.
m_ResetEvent = new ManualResetEvent(false);
// initialize the security options
SecurityOptions options = new SecurityOptions(
SecureProtocol.Ssl3 | SecureProtocol.Tls1, // use SSL3 or TLS1
null, // do not use client authentication
ConnectionEnd.Client, // this is the client side
CredentialVerification.None, // do not check the certificate -- this should not be used in a real-life application :-)
null, // not used with automatic certificate verification
"www.microsoft.com", // this is the common name of the Microsoft web server
SecurityFlags.Default, // use the default security flags
SslAlgorithms.SECURE_CIPHERS, // only use secure ciphers
null); // do not process certificate requests.
try {
// create the securesocket with the specified security options
m_Socket = new SecureSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, options);
// resolve www.microsoft.com
IPEndPoint endpoint = new IPEndPoint(Dns.GetHostEntry("www.microsoft.com").AddressList[0], 443);
// start connecting to www.microsoft.com
m_Socket.BeginConnect(endpoint, new AsyncCallback(this.OnConnect), null);
// wait until the entire web page has been received
m_ResetEvent.WaitOne();
// close the SecureSocket
m_Socket.Close();
} catch {
OnError("Could not connect to the website");
}
}