The Secure property determines if a secure connection is
established to the server. The default value for this property is
False, which specifies that a standard connection to the server is
used. To establish a secure connection, the application should set
this property value to True prior to calling the Connect
method. Once the connection has been established, the client may
request files or submit queries to the server as with standard
connections.
It is possible for an application to establish a non-secure
connection, and then switch to a secure connection at some later
point during the session. Initially set the Secure property to
False, then connect to the server normally. Once the connection has
been established, setting the Secure property to True will
cause the control to negotiate a secure connection with the remote
host. If the socket was created using the Accept method, the
control will block and wait for the client to begin the negotiation.
If the socket was created using the Connect method, it will
immediately begin the negotiation with the server. Note that if a
non-blocking (asynchronous) socket is being used, the application
must wait to set the Secure property to True after the
OnConnect event has fired.
Setting the Secure property to False during a connection
will cause the control to send a shutdown message to the remote host.
This may cause which may cause it to terminate the connection,
however it will not close the socket. It is recommended that
applications do not set the Secure property to False after a
secure connection has been established, and instead use the
Disconnect method to close the connection.
It is recommended that the application use exception handling to
catch any errors that may occur when changing the value of this
property. If the control is unable to initialize the Windows security
libraries, an exception will be thrown when this property value is
modified.
The following example establishes a secure connection to a
web server:
SocketWrench1.HostName = strHostName
SocketWrench1.RemotePort = 443
SocketWrench1.Secure = True
nError = SocketWrench1.Connect()
If nError > 0 Then
MsgBox "Unable to connect to server " & strHostName, vbExclamation
Exit Sub
End If
If SocketWrench1.CertificateStatus <> swCertificateValid Then
nResult = MsgBox("The server certificate could not be validated" & vbCrLf & _
"Are you sure you wish to continue?", vbYesNo)
If nResult = vbNo Then
SocketWrench1.Disconnect
Exit Sub
End If
End If