Org.Mentalis.Security.Ssl.SecureSocket.BeginConnect C# (CSharp) Method

BeginConnect() public method

Begins an asynchronous request for a connection to a network device.
is a null reference (Nothing in Visual Basic). An operating system error occurs while creating the SecureSocket. The SecureSocket has been closed.
public BeginConnect ( EndPoint remoteEP, AsyncCallback callback, object state ) : IAsyncResult
remoteEP System.Net.EndPoint An that represents the remote device.
callback AsyncCallback The delegate.
state object An object that contains state information for this request.
return IAsyncResult
		public override IAsyncResult BeginConnect(EndPoint remoteEP, AsyncCallback callback, object state) {
			if (SecureProtocol == SecureProtocol.None)
				return base.BeginConnect(remoteEP, callback, state);
			// secure BeginConnect
			if (remoteEP == null)
				throw new ArgumentNullException();
			if (m_ConnectResult != null)
				throw new SocketException(); // BeginConnect already called
			AsyncResult ret = new AsyncResult(callback, state, null);
			m_ConnectResult = ret;
			base.BeginConnect(remoteEP, new AsyncCallback(OnConnect), null);
			return ret;
		}
		/// <summary>

Usage Example

 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");
     }
 }
All Usage Examples Of Org.Mentalis.Security.Ssl.SecureSocket::BeginConnect