r/codedbyhand • u/emnotbr • 17d ago
How to implement Keep alive connection in an HTTP low level Socket connection?
I was trying to recreate an HTTP/HTTPS request Library in C. I want to implement and use the Connection: keep-alive header in my program. I started with setsockopt() all that jazz to set it up, but it still doesn't work. When I start the program for a connection: close, it prints out the html, however whenever I do it for a keep-alive, it just keeps running without ever printing anything.
15
Upvotes
4
u/YouPeopleCantBeReal4 17d ago
If you’re using http, to keep a connection live you would use websockets which is HTTP/1.1 since that is the http level that introduced persistent connection
2
u/emnotbr 17d ago
Wait nvm I had to set the HTTP version to 1.0 lol. But why does that work?