May 2019
Intermediate to advanced
478 pages
11h 21m
English
We begin our TCP client by including the header file, chap03.h, which was printed at the beginning of this chapter. This header file includes the various other headers and macros we need for cross-platform networking:
/*tcp_client.c*/#include "chap03.h"
On Windows, we also need the conio.h header. This is required for the _kbhit() function, which helps us by indicating whether terminal input is waiting. We conditionally include this header, like so:
/*tcp_client.c*/#if defined(_WIN32)#include <conio.h>#endif
We can then begin the main() function and initialize Winsock:
/*tcp_client.c*/int main(int argc, char *argv[]) {#if defined(_WIN32) WSADATA d; if (WSAStartup(MAKEWORD(2, 2), &d)) { fprintf(stderr, "Failed to initialize.\n"); ...
Read now
Unlock full access