I'm creating a very simple http server for an assignment for my course.
It will handle GET and HEAD requests appropriately.
So far, My server sees the clients connect, and sends the same response to each of them (intentional, for testing).
if I don't give the clients a response (and leave the web browsers loading), and then close the web browser (as the page is loading), my server sees that the client disconnected.
However, when I send a response to them (which is just a status line, 2 or 3 header fields, and some html to give the web pages a title), they successfully display the web page (just the title for now, as intended), but my server doesn't see them disconnect anymore when I close the web browser/tab.
Here is the response I'm sending to all the clients:
char resp[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 53\r\nConnection: keep-alive\r\n\r\n<html><head><title>Dan's Server</title></head></html>\0";
Note: I write strlen(resp) bytes to the socket, i.e I don't write the final zero byte to the socket.
Another note: Something else I noticed when testing just now was that if I connect 2 clients 1 after the other (my server is multi threaded), the second connection doesn't show up as a new one. This only happens when I respond to them though (weird?). If I don't respond, my server sees them as separate connections.