Partager via


Implementing a Secure Socket

The following procedure describes how to establish a secure socket connection.

To implement a secure socket

  1. Create a socket with the socket function.
  2. Set the socket in secure mode with the setsockopt function. Set level to SO_SOCKET, optname to SO_SECURE, and optval to a DWORD set to SO_SEC_SSL.
  3. Specify the certificate validation callback function by calling WSAIoctl with the SO_SSL_SET_VALIDATE_CERT_HOOK control code.
  4. To specify a particular security protocol, call WSAIoctl with the SO_SSL_GET_PROTOCOLS control code to determine the default protocols. Then call WSAIoctl with the SO_SSL_SET_PROTOCOLS control code to select the protocols to be enabled. Otherwise, Windows CE selects the protocol.
  5. Make a connection with the connect function.
  6. The certificate callback function is automatically called. The connection can be completed only if the callback function verifies the acceptability of the certificate by returning SSL_ERR_OKAY.
  7. Transmit and send.
  8. The send and recv functions automatically encode and decode data.
  9. When you are finished, close the socket with the closesocket function.

See Also

Winsock Secure Sockets

 Last updated on Saturday, April 10, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.