Time server example

In this chapter, we develop a simple time server that displays the time to an HTTPS client. This program is an adaptation of time_server.c from Chapter 2, Getting to Grips with Socket APIs, which served the time over plain HTTP. Our program begins by including the chapter header, defining main(), and initializing Winsock on Windows. The code for this is as follows:

/*tls_time_server.c*/#include "chap10.h"int main() {#if defined(_WIN32)    WSADATA d;    if (WSAStartup(MAKEWORD(2, 2), &d)) {        fprintf(stderr, "Failed to initialize.\n");        return 1;    }#endif

The OpenSSL library is then initialized with the following code:

/*tls_time_server.c continued*/       SSL_library_init();    OpenSSL_add_all_algorithms();    SSL_load_error_strings();

An ...

Get Hands-On Network Programming with C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.