Click here to Skip to main content
15,891,951 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: What makes C and C++ a "good" language? Pin
pasztorpisti25-Sep-12 5:45
pasztorpisti25-Sep-12 5:45 
AnswerRe: What makes C and C++ a "good" language? Pin
Member 929954619-Sep-12 2:49
Member 929954619-Sep-12 2:49 
AnswerRe: What makes C and C++ a "good" language? Pin
Stefan_Lang21-Sep-12 0:22
Stefan_Lang21-Sep-12 0:22 
AnswerRe: What makes C and C++ a "good" language? Pin
Rajesh R Subramanian25-Sep-12 1:14
professionalRajesh R Subramanian25-Sep-12 1:14 
GeneralRe: What makes C and C++ a "good" language? Pin
CPallini25-Sep-12 2:22
mveCPallini25-Sep-12 2:22 
AnswerRe: What makes C and C++ a "good" language? Pin
ErnestoNet25-Sep-12 6:44
ErnestoNet25-Sep-12 6:44 
QuestionAudio creation/conversion SDK's Pin
Member 929954618-Sep-12 6:27
Member 929954618-Sep-12 6:27 
Questionsocket read on a keep alive request waits until connection timeout - II Pin
Jayapal Chandran17-Sep-12 20:36
Jayapal Chandran17-Sep-12 20:36 
How to know whether the server has no data while reading the response of a request which is keep alive because the socket read function waits for the server to send data if we have made a request with keep alive option.

I am writing a socket program to fetch a webpage.

My request header has no connection close header so by default the connection is keep alive.

I open a connection, send the request header using socket_write and getting using a while loop to receive data
if it is a Connection Close request the everything works well.

if it is keep alive and after i have read the content the socket_read function is still waiting for data which causes the code to hand in there.

Here how do we know whether the server has completed sending the resource though it is keep alive...

i have a work around like checking the content-length response header to know how much data is received and accordingly i can stop reading

or

if response header has transfer-encoding as chunked then i can write more code to find the end of the response

yet without the above two workarounds how to check whether the socket_recv is still waiting for data?

Besides, i was thinking that since we are setting the read buffer length (like 1024 in this code) and the socket_recv is returning the no of bytes read and if the bytes read is less than 1024 then i can assume that the next read will not return anything and by this time i can quit the while loop.... BUT http server sends different length response so my logic will not work.

Here is my request header and the while loop in which i receive date from the server

//i have commented the connection close header so that by default it will be keep alive

here the code is in different language but the basic concept is the same for all languages so i am asking it here.

PHP
$o = 'GET /search?hl=en&q='.$query.'&start='.$start.' HTTP/1.1'."\r\n";
$o.= 'Host: www.google.co.in'."\r\n";
$o.= 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0'."\r\n";
//$o.= 'Connection: close'."\r\n";
$o.= "\r\n";

//writing $o to the socket resource

//receiving the response

do
{
    $bytes = socket_recv($f, $tbuf, 1024, 0x40);

    if($bytes === false)
              die("\r\nUnable to read headers - ".socket_strerror(socket_last_error()));

    echo "\r\n".$bytes;

    if(!$bytes)break;

    $buf.= $tbuf;
}while(1);


In the above code after i have received the complete html of a webpage the control is in the line where i am reading the response. Which i assume the code is still waiting for data from the server.

Suggestions, comments and advice's are welcome.

http://vikku.info/

Today's Beautiful Moments are
Tomorrow's Beautiful Memories


AnswerCrosspost Pin
Peter_in_278017-Sep-12 20:55
professionalPeter_in_278017-Sep-12 20:55 
GeneralRe: Crosspost Pin
Jayapal Chandran18-Sep-12 11:12
Jayapal Chandran18-Sep-12 11:12 
AnswerRe: socket read on a keep alive request waits until connection timeout - II Pin
pasztorpisti17-Sep-12 21:23
pasztorpisti17-Sep-12 21:23 
GeneralRe: socket read on a keep alive request waits until connection timeout - II Pin
Jayapal Chandran18-Sep-12 11:13
Jayapal Chandran18-Sep-12 11:13 
GeneralRe: socket read on a keep alive request waits until connection timeout - II Pin
pasztorpisti18-Sep-12 12:09
pasztorpisti18-Sep-12 12:09 
QuestionMultiple selection in Tree control(Non MFC) Pin
Ram Shelke17-Sep-12 20:10
Ram Shelke17-Sep-12 20:10 
AnswerRe: Multiple selection in Tree control(Non MFC) Pin
Richard MacCutchan17-Sep-12 22:35
mveRichard MacCutchan17-Sep-12 22:35 
GeneralRe: Multiple selection in Tree control(Non MFC) Pin
Ram Shelke17-Sep-12 23:01
Ram Shelke17-Sep-12 23:01 
GeneralRe: Multiple selection in Tree control(Non MFC) Pin
Richard MacCutchan17-Sep-12 23:12
mveRichard MacCutchan17-Sep-12 23:12 
AnswerRe: Multiple selection in Tree control(Non MFC) Pin
Chris Meech18-Sep-12 3:59
Chris Meech18-Sep-12 3:59 
GeneralRe: Multiple selection in Tree control(Non MFC) Pin
Richard MacCutchan18-Sep-12 4:10
mveRichard MacCutchan18-Sep-12 4:10 
GeneralRe: Multiple selection in Tree control(Non MFC) Pin
Chris Meech18-Sep-12 4:15
Chris Meech18-Sep-12 4:15 
QuestionSingle system instance Pin
Taria16-Sep-12 23:16
Taria16-Sep-12 23:16 
AnswerRe: Single system instance PinPopular
Jochen Arndt16-Sep-12 23:35
professionalJochen Arndt16-Sep-12 23:35 
GeneralRe: Single system instance Pin
Michael Haephrati18-Sep-12 10:48
professionalMichael Haephrati18-Sep-12 10:48 
QuestionHow to recognize a table in a pdf file Pin
LuigiSc216-Sep-12 4:10
LuigiSc216-Sep-12 4:10 
AnswerRe: How to recognize a table in a pdf file Pin
Mohibur Rashid16-Sep-12 4:40
professionalMohibur Rashid16-Sep-12 4:40 

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.