TCP server code

Our TCP server code begins by including the needed headers, starting main(), and initializing Winsock. Refer to Chapter 2Getting to Grips with Socket APIs, if this doesn't seem familiar:

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

We then get our local address, create our socket, and bind(). This is all done exactly as explained in Chapter 2, Getting to Grips with Socket APIs:

/*tcp_serve_toupper.c */    printf("Configuring local address...\n");    struct addrinfo hints;    memset(&hints, 0, sizeof(hints));    hints.ai_family = AF_INET;    hints.ai_socktype = SOCK_STREAM; hints.ai_flags ...

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.