COMS 3157 Advanced Programming

14 - Sockets and HTTP


UNIX I/O using file descriptors

Big-endian vs. Little-endian

Sockets API

Recommended reading & reference:

Lecture slides: Sockets API and HTTP 1.0

TCP Client & Server code examples:

IPv4 address structures

struct sockaddr {
    sa_family_t sa_family;
    char        sa_data[14];

struct sockaddr_in {
    sa_family_t    sin_family; /* address family: AF_INET */
    in_port_t      sin_port;   /* port in network byte order */
    struct in_addr sin_addr;   /* internet address */

struct in_addr {
    uint32_t       s_addr;     /* address in network byte order */

Sockets API Functions

send(int socket, const void *buffer, size_t length, int flags)
recv(int socket, void *buffer, size_t length, int flags)


Recommended reading & reference:

HTTP protocol in action:

HTTP 1.0 v. HTTP 1.1

Dynamic web page