Click here to Skip to main content
15,851,387 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: [edit: most problems fixed, one problem remaining] Invalidate rectangle follow up, flickering and no movement Pin
Mircea Neacsu10-Dec-23 3:03
Mircea Neacsu10-Dec-23 3:03 
AnswerRe: [edit: most problems fixed, one problem remaining] Invalidate rectangle follow up, flickering and no movement Pin
Richard MacCutchan10-Dec-23 3:20
mveRichard MacCutchan10-Dec-23 3:20 
GeneralRe: [edit: most problems fixed, one problem remaining] Invalidate rectangle follow up, flickering and no movement Pin
Calin Negru10-Dec-23 5:48
Calin Negru10-Dec-23 5:48 
Questiondownload a web page Pin
mike74116-Dec-23 5:30
mike74116-Dec-23 5:30 
AnswerRe: download a web page Pin
Mircea Neacsu6-Dec-23 6:00
Mircea Neacsu6-Dec-23 6:00 
GeneralRe: download a web page Pin
mike74116-Dec-23 14:28
mike74116-Dec-23 14:28 
GeneralRe: download a web page Pin
Mircea Neacsu6-Dec-23 15:18
Mircea Neacsu6-Dec-23 15:18 
AnswerRe: download a web page Pin
jschell6-Dec-23 7:52
jschell6-Dec-23 7:52 
mike7411 wrote:
get stuck in the recv function.


I suspect that none of the suggestions in the other post are going to help with this.

Your design is wrong. The message flow looks like this.
- Client- Open socket (server accepts)
- Client- Send request
- Server- Sends response
- Client- Read request
- Client- Closes socket

Notice in the above the server does nothing to terminate the message stream. The client is responsible, not the server.

So recv() sits there waiting for a message that the server will never send.

The HTTP protocol defines a request and then a response.

You however are not following that protocol. At a minimum you are missing the following
1 - You are not checking for a HTTP error code.
2 - You are not reading the 'content-length' header attribute.
3 - You are not looking for the response body.

If you were doing the second then you would use that to read to the end of the message using the content-length. That specifically defines how many bytes the server should send in the response body

Additionally there are additional error conditions that good code must expect
- The content-length might be missing. Invalid HTTP but one must still anticipate that.
- The content-length is too long. Very difficult to deal with. And it still results in the problem you are seeing. So you must add a timeout. Google for how to do that.

What about if the content-length is too short? Myself I just ignore that case. Because in most cases content-length will always be right. And too short might lead to other problems but you have no way to detect that unless you always do a timeout read, and that will slow the application to no point (again because it almost always will be right.)
AnswerRe: download a web page Pin
Gerry Schmitz6-Dec-23 8:28
mveGerry Schmitz6-Dec-23 8:28 
Questioncopying a file in C++17 Pin
mike74115-Dec-23 22:36
mike74115-Dec-23 22:36 
AnswerRe: copying a file in C++17 Pin
Richard MacCutchan5-Dec-23 23:07
mveRichard MacCutchan5-Dec-23 23:07 
AnswerRe: copying a file in C++17 Pin
jschell6-Dec-23 8:04
jschell6-Dec-23 8:04 
Questionprintf without stdio.h Pin
mike74115-Dec-23 6:21
mike74115-Dec-23 6:21 
AnswerRe: printf without stdio.h Pin
Mircea Neacsu5-Dec-23 6:31
Mircea Neacsu5-Dec-23 6:31 
GeneralRe: printf without stdio.h Pin
mike74115-Dec-23 17:23
mike74115-Dec-23 17:23 
GeneralRe: printf without stdio.h Pin
Mircea Neacsu5-Dec-23 17:42
Mircea Neacsu5-Dec-23 17:42 
AnswerRe: printf without stdio.h Pin
Victor Nijegorodov5-Dec-23 6:32
Victor Nijegorodov5-Dec-23 6:32 
AnswerRe: printf without stdio.h Pin
k50545-Dec-23 7:02
mvek50545-Dec-23 7:02 
GeneralRe: printf without stdio.h Pin
jschell6-Dec-23 8:07
jschell6-Dec-23 8:07 
Questioncopying a file Pin
mike74115-Dec-23 4:24
mike74115-Dec-23 4:24 
AnswerRe: copying a file Pin
Mircea Neacsu5-Dec-23 4:32
Mircea Neacsu5-Dec-23 4:32 
AnswerRe: copying a file Pin
Richard MacCutchan5-Dec-23 5:05
mveRichard MacCutchan5-Dec-23 5:05 
AnswerRe: copying a file Pin
k50545-Dec-23 5:42
mvek50545-Dec-23 5:42 
QuestionMyth of a Myth? Pin
jschell4-Dec-23 4:38
jschell4-Dec-23 4:38 
AnswerRe: Myth of a Myth? Pin
Richard MacCutchan4-Dec-23 5:57
mveRichard MacCutchan4-Dec-23 5:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.