Linux C Socket: Blocked on recv call

前端 未结 2 953
不知归路
不知归路 2021-01-24 02:51

In my application i have created a thread for a simple http server, then from within my application i tried to connect to http server but control is blocked/hanged on recv call.

2条回答
  •  鱼传尺愫
    2021-01-24 03:11

    You need to either send an HTTP 1.0 header, or else read about content-length in HTTP 1.1. You are reading the stream to EOS when the server is under no obligation to close the connection, so you block. The Content-Length header tells you how much data is in the body: you should only try to read that many bytes.

    If you specify HTTP 1.0 (and no fancy headers) the server will close the connection after sending the response.

提交回复
热议问题