Making it networked

Now that we've worked out our program's functionality, we can begin on the networked version of the same program.

To begin with, we include the needed headers:

/*time_server.c*/#if defined(_WIN32)#ifndef _WIN32_WINNT#define _WIN32_WINNT 0x0600#endif#include <winsock2.h>#include <ws2tcpip.h>#pragma comment(lib, "ws2_32.lib")#else#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#include <unistd.h>#include <errno.h>#endif

As we discussed earlier, this detects if the compiler is running on Windows or not and includes the proper headers for the platform it is running on.

We also define some macros, which abstract out some of the difference between the Berkeley socket ...

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.