1

This is for a c++ implementation of http using winsock2. I'm sending the required headers, but because of the flow of the application, I cannot know the length of the content.

According to the protocol, closing the connection should signal a normal end to the body as long as I specify Connection: closein the headers, which I'm doing.

Right after sending the body, I call closesocket(socket) to close the connection, but chrome puts out an error saying The connection was reset..

If I comment that out, it displays the body, but never finishes loading since the connection is still active.

Am I closing the socket in the wrong way? Or am I missing something with the http protocol with regards to the end of content?

I've been reading up on this all day and I'm coming up with nothing

WinterDev
  • 348
  • 1
  • 11
  • 1
    The usual mechanism for sending the response of unknown length is [`Transfer-Encoding: chunked`](https://en.wikipedia.org/wiki/Chunked_transfer_encoding) – Igor Tandetnik Apr 29 '17 at 17:32
  • Related: http://stackoverflow.com/questions/8872988/properly-close-a-tcp-socket – jarmod Apr 29 '17 at 17:33
  • @jarmod Thanks, I wasn't reading the socket stream after closing, which was causing the error. I just needed to shutdown, read and then close. – WinterDev Apr 29 '17 at 17:45

0 Answers0