Home > other >  Using C language to write multithreaded HTTP server, it is when you need to close the socket?
Using C language to write multithreaded HTTP server, it is when you need to close the socket?

Time:10-28

I met in the process of learning the HTTP server is a bit difficult,

I accept to a socket, and built a thread to the browser for data exchange,

The browser to open the server index. The HTML will soon request many images,
What circumstance can close off the socket? Can't have been attached to the?

My index. The inside of the HTML image, if appears twice in a web page, will download not,

Use printf I print down, found that the server did not receive these two pictures request,
Other pictures all download only appear once in

Where may write wrong,

Excuse me, what should pay attention to this problem?

============================
Update: listenfd=socket () the socket I haven't been shut,
But clientfd=the accept (); I use this socket is turned off, the above problem solved,
But I heard that HTTP 1.1 is a long connection, do not need to close the socket, I am a little to be received,
Please don't really need to close off clientfd? If so, then how to solve my above status "?

CodePudding user response:

The data of the picture after the charge can be closed

CodePudding user response:

Don't need to close the socket refers to the service side,,, not to close the client socket how do for the next transmission,,

CodePudding user response:

On the same page pictures of normal browser will ask only once?
When the data sending or receiving end can close
  • Related