Click here to Skip to main content
12,349,554 members (28,998 online)

Web Development

 
AnswerRe: variable element id Pin
Sebastiaan Meijerink30-Oct-12 4:08
memberSebastiaan Meijerink30-Oct-12 4:08 
QuestionGet webcam capture Pin
Killzone DeathMan21-Sep-12 1:16
memberKillzone DeathMan21-Sep-12 1:16 
AnswerRe: Get webcam capture Pin
Joan Murt22-Sep-12 1:31
memberJoan Murt22-Sep-12 1:31 
GeneralRe: Get webcam capture Pin
Killzone DeathMan22-Sep-12 11:10
memberKillzone DeathMan22-Sep-12 11:10 
AnswerMessage Automatically Removed Pin
19-Oct-12 22:00
membersarlishah19-Oct-12 22:00 
QuestionHUGE Web Service Performance Issue Pin
Jammer21-Sep-12 0:53
memberJammer21-Sep-12 0:53 
AnswerRe: HUGE Web Service Performance Issue Pin
jkirkerx21-Sep-12 11:04
memberjkirkerx21-Sep-12 11:04 
GeneralRe: HUGE Web Service Performance Issue Pin
Mohibur Rashid22-Sep-12 3:00
memberMohibur Rashid22-Sep-12 3:00 
GeneralRe: HUGE Web Service Performance Issue Pin
jkirkerx22-Sep-12 8:35
memberjkirkerx22-Sep-12 8:35 
GeneralRe: HUGE Web Service Performance Issue Pin
manak chand22-Oct-12 0:24
membermanak chand22-Oct-12 0:24 
SuggestionStore the history of links the user visits of any browser Pin
VijayChauhan12319-Sep-12 18:21
memberVijayChauhan12319-Sep-12 18:21 
GeneralRe: Store the history of links the user visits of any browser Pin
Andrei Straut19-Sep-12 21:09
memberAndrei Straut19-Sep-12 21:09 
GeneralRe: Store the history of links the user visits of any browser Pin
S.M. Zamshed Farhan12-Jan-13 15:31
memberS.M. Zamshed Farhan12-Jan-13 15:31 
Questionsocket read on a keep alive request waits until connection timeout Pin
Jayapal Chandran17-Sep-12 4:50
memberJayapal Chandran17-Sep-12 4:50 
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

$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


QuestionPHP Pin
dashing_z14-Sep-12 14:23
memberdashing_z14-Sep-12 14:23 
AnswerRe: PHP Pin
Mike-MadBadger14-Sep-12 20:43
memberMike-MadBadger14-Sep-12 20:43 
GeneralRe: PHP Pin
Joan Murt17-Sep-12 1:00
memberJoan Murt17-Sep-12 1:00 
SuggestionRe: PHP Pin
Mohibur Rashid16-Sep-12 4:22
memberMohibur Rashid16-Sep-12 4:22 
AnswerRe: PHP Pin
Joan Murt17-Sep-12 0:59
memberJoan Murt17-Sep-12 0:59 
AnswerRe: PHP Pin
Killzone DeathMan21-Sep-12 1:03
memberKillzone DeathMan21-Sep-12 1:03 
AnswerRe: PHP Pin
Mighty Raju27-Sep-12 2:58
memberMighty Raju27-Sep-12 2:58 
AnswerRe: PHP Pin
ramonwilson1-Oct-12 22:21
memberramonwilson1-Oct-12 22:21 
AnswerRe: PHP Pin
S.M. Zamshed Farhan12-Jan-13 15:33
memberS.M. Zamshed Farhan12-Jan-13 15:33 
QuestionCSS Placeholder question Pin
spankyleo12312-Sep-12 1:47
memberspankyleo12312-Sep-12 1:47 
AnswerRe: CSS Placeholder question Pin
mark merrens12-Sep-12 5:36
membermark merrens12-Sep-12 5:36 
Questionwhat is camera icon beside image search of google Pin
hosseinDolat11-Sep-12 21:44
memberhosseinDolat11-Sep-12 21:44 
AnswerRe: what is camera icon beside image search of google Pin
Sandeep Mewara11-Sep-12 22:18
mvpSandeep Mewara11-Sep-12 22:18 
GeneralRe: what is camera icon beside image search of google Pin
hosseinDolat12-Sep-12 0:25
memberhosseinDolat12-Sep-12 0:25 
GeneralRe: what is camera icon beside image search of google Pin
Sandeep Mewara12-Sep-12 0:35
mvpSandeep Mewara12-Sep-12 0:35 
AnswerRe: what is camera icon beside image search of google Pin
Mohibur Rashid11-Sep-12 23:42
memberMohibur Rashid11-Sep-12 23:42 
GeneralRe: what is camera icon beside image search of google Pin
hosseinDolat12-Sep-12 0:24
memberhosseinDolat12-Sep-12 0:24 
GeneralRe: what is camera icon beside image search of google Pin
Mohibur Rashid12-Sep-12 1:40
memberMohibur Rashid12-Sep-12 1:40 
AnswerRe: what is camera icon beside image search of google Pin
Shameel17-Sep-12 5:15
memberShameel17-Sep-12 5:15 
GeneralRe: what is camera icon beside image search of google Pin
hosseinDolat17-Sep-12 17:43
memberhosseinDolat17-Sep-12 17:43 
QuestionPHP Email Pin
chandra reinhart11-Sep-12 5:28
memberchandra reinhart11-Sep-12 5:28 
AnswerRe: PHP Email Pin
Richard A. Abbott11-Sep-12 9:53
memberRichard A. Abbott11-Sep-12 9:53 
GeneralRe: PHP Email Pin
chandra reinhart11-Sep-12 13:29
memberchandra reinhart11-Sep-12 13:29 
GeneralRe: PHP Email Pin
Richard A. Abbott11-Sep-12 22:12
memberRichard A. Abbott11-Sep-12 22:12 
GeneralRe: PHP Email Pin
chandra reinhart11-Sep-12 22:47
memberchandra reinhart11-Sep-12 22:47 
GeneralRe: PHP Email Pin
Richard A. Abbott12-Sep-12 0:25
memberRichard A. Abbott12-Sep-12 0:25 
QuestionSearch action should be an HTTP GET or a POST? Pin
AlexCode11-Sep-12 0:23
memberAlexCode11-Sep-12 0:23 
AnswerRe: Search action should be an HTTP GET or a POST? Pin
Eddy Vluggen11-Sep-12 2:16
memberEddy Vluggen11-Sep-12 2:16 
GeneralRe: Search action should be an HTTP GET or a POST? Pin
AlexCode11-Sep-12 2:47
memberAlexCode11-Sep-12 2:47 
GeneralRe: Search action should be an HTTP GET or a POST? Pin
Eddy Vluggen11-Sep-12 5:32
memberEddy Vluggen11-Sep-12 5:32 
AnswerRe: Search action should be an HTTP GET or a POST? Pin
S.M. Zamshed Farhan12-Jan-13 15:35
memberS.M. Zamshed Farhan12-Jan-13 15:35 
QuestionHTML table oddity Pin
DavidCrow10-Sep-12 11:01
memberDavidCrow10-Sep-12 11:01 
AnswerRe: HTML table oddity Pin
Peter_in_278010-Sep-12 13:11
memberPeter_in_278010-Sep-12 13:11 
GeneralRe: HTML table oddity Pin
DavidCrow11-Sep-12 3:38
memberDavidCrow11-Sep-12 3:38 
AnswerRe: HTML table oddity Pin
AspDotNetDev10-Sep-12 13:15
protectorAspDotNetDev10-Sep-12 13:15 
GeneralRe: HTML table oddity Pin
DavidCrow11-Sep-12 3:44
memberDavidCrow11-Sep-12 3:44 

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.


Advertise | Privacy | Mobile
Web01 | 2.8.160621.1 | Last Updated 24 Jun 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid