> #include <sys/types.h>
> #include <sys/socket.h>
> #include <netinet/ip.h>
> #include <string.h>
> #include <unistd.h>
> #include <stdio.h>
>
>
> int main(int argc, char *argv[])
> {
> int listen_fd;
> int fd;
> struct sockaddr_storage addr;
> socklen_t addrlen = sizeof(addr);
> struct sockaddr_in addr_in;
> struct linger l = {1, 0};
> int val = 1;
> char buffer[1024];
> char response[] = "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n";
>
> listen_fd = socket(PF_INET, SOCK_STREAM, 0);
> memset(&addr_in, 0, sizeof(struct sockaddr_in));
> addr_in.sin_family = AF_INET;
> addr_in.sin_port = ntohs(8080);
> setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof val);
> bind(listen_fd, &addr_in, sizeof(addr_in));
> listen(listen_fd, 50);
> fd = accept(listen_fd, &addr, &addrlen);
> read(fd, buffer, sizeof(buffer));
> write(fd, (void *)response, strlen(response));
> printf("%s\n", response);
> read(fd, buffer, sizeof(buffer));
> setsockopt(fd, SOL_SOCKET, SO_LINGER, &l, sizeof l);
> close(fd); /* sends TCP RST rather than FIN */
> return 0;
> }
>
> It just closes down the connection with a RST on the second request on the
> same connection. You will notice in the network sniffer that the browser
> opens
> a new TCP connection and resends the request.
Hah, you beat me to it. I was going to do the same thing. Thanks Rudiger!
Adam