UNIX I/O using file descriptors
Big-endian vs. Little-endian
endian-demo.c
Recommended reading & reference:
Beej’s Guide to Network Programming
Lecture slides: Sockets API and HTTP 1.0
TCP Client & Server code examples:
tcp-echo-client.c
, tcp-echo-server.c
tcp-sender.c
, tcp-recver.c
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 */
};
send(int socket, const void *buffer, size_t length, int flags)
send()
blocks until it sends all bytes requestedsend(sock, buf, len, 0)
is equivalent to write(sock, buf, len)
recv(int socket, void *buffer, size_t length, int flags)
recv()
blocks until it has received at least 1 byterecv(sock, buf, len, 0)
is equivalent to read(sock, buf, len)
MSG_WAITALL
flag changes this behavior – it requests that the operation block until the
full request is satisfied.Recommended reading & reference:
HTTP protocol in action:
HTTP 1.0 v. HTTP 1.1
Dynamic web page
HTML form:
<form method=GET action="/mdb-lookup">
Lookup: <input type="text" name="key">
<p>
<input type="submit" value="Lookup">
</form>
when the text box is filled with “abc” and button clicked, the browser sends:
GET /mdb-lookup?key=abc HTTP/1.1
How do dynamic web sites manage sessions?
Server “feeds” cookie at the start of session:
HTTP/1.1 200 OK
Content-type: text/html
Set-Cookie: name=value
Browser stores the cookies in a local file, indexed by web sites, and on subsequent visits, it brings the corresponding cookie along:
GET /index.html HTTP/1.1
Cookie: name=value