Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 29th, 2006, 9:54 AM   #1
hbe02
Hobbyist Programmer
 
hbe02's Avatar
 
Join Date: Mar 2006
Location: Lebanon
Posts: 148
Rep Power: 3 hbe02 is on a distinguished road
Web Client

im trying to extract information from a website..
Ive tested my client on my university's email login page
IP is
"193.188.129.122"
i dont know when to stop reading.. i never get the
Connection: close\r\n
in what case do i exit this loop?
while(flag == true)
	{
		char * reply = new char[1024];
		recv(com->sd,reply,1024,0);
		
		
		delete [] reply;	
	}
this is the output my program gives:
Communication With Server on Socket 1992 Initiated
Sending: GET / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-
excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwav
e-flash, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322
; .NET CLR 2.0.50727)
Host: 192.168.141.107
Connection: Keep-Alive


RECIEVING
HTTP/1.1 200 OK
Date: Fri, 29 Sep 2006 14:23:36 GMT
Server: Apache/1.3.33 Ben-SSL/1.55 (Unix) PHP/4.3.4
X-Powered-By: PHP/4.3.4
Set-Cookie: Horde=5bf5563986bdcf4b05cc5e03ea9c8e82; path=/; domain=192.168.141.1
07
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=ISO-8859-1

e16
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-trans
itional.dtd">
<!-- IMP: Copyright 2001, The Horde Project. IMP is under the GPL. -->
<!-- Horde Project: http://horde.org/ | IMP: http://horde.org/imp/ -->
<!--    GNU Public License: http://www.fsf.org/copyleft/gpl.html   -->
<html lang="en-US"><head>
<title>Imail :: Welcome to Imail</title>
<link rel="SHORTCUT ICON" href="/imp/graphics/favicon.ico" type="image/x-icon" /
>
<link href="/css.php?app=imp" rel="stylesheet" type="text/css" />
</head>

<bo
.
.
.
more html stuff
.
.
.
<BR>
<table>
</tr></table>

</body>
</html>
<!--
<div align=center>
<br><br>
<table border="0" width="55%" style="border-style: dotted; border-width:
1px" bgcolor="#444466">
        <tr>
                <td>
                <p align="center" dir="ltr"><font color="#FFFFFF"><b>IMPORTANT
NOTICE:</b></font><br>
                <br>
                <font color="#FFFFFF">-</font> <a href="http://www.aub.edu.lb/we
bmail/"><font
color="#FF0000">WEBMAIL</font></a> <font color="#FFFFFF">is
                being phased out but can still be accessed at:</font><br>
        <a href="http://www.aub.edu.lb/webmail/">
                <font
color="#FF0000">http://www.aub.edu.lb/webmail/</font></a><br>
                <br><font color="#FFFFFF">- Support to Webmail will end
soon! So, please You are urged to export all your messages from Webmail to Imail
 by sending a request to imail@aub.edu.lb.</a><br>
              <br>  (This notice is for AUB faculty members only)</
4c
font>
</p>
                <p>&nbsp;</td>
        </tr>
</table>
</div>
-->

0

════════════════════════════════════════════════════════════════════════════════
════════════════════════════════════════════════════════════════════════════════
════════════════════════════════════════════════════════════════════════════════
════════════════════════════════════════════════════════════════════════════════
════════════════════════════════════════════════════════════════════════════════
════════════════════════════════════════════════════════════════════════════════
════════════════════════════════════════════════════════════════════════════════
════════════════════════════════════════════════════════════════════════════════
════════════════════════════════════════════════════════════════════════════════
════════════════════════════════════════════════════════════════════════════════
════════════════════════════════════════════════════════════════════════════════
════════════════════════════════════════════════════
then the program hangs until the timeout on the website, then bursts out "=======" forever.. i guess this is becasue the website cut the TCP connection after the timeout and my program continued to recieve and output the result..
hbe02 is offline   Reply With Quote
Old Sep 29th, 2006, 1:06 PM   #2
sarumont
Hobbyist Programmer
 
sarumont's Avatar
 
Join Date: Apr 2004
Location: /dev/urandom
Posts: 154
Rep Power: 5 sarumont is on a distinguished road
Send a message via ICQ to sarumont Send a message via AIM to sarumont Send a message via Yahoo to sarumont
You are opening a persistent connection.

Connection: Keep-Alive

This is most likely due to HTTP/1.1; try using HTTP/1.0.
__________________
"Time is an illusion. Lunchtime doubly so."
-the late, great Douglas Adams
sarumont is offline   Reply With Quote
Old Oct 1st, 2006, 12:21 AM   #3
climbnorth
Newbie
 
Join Date: Oct 2006
Posts: 16
Rep Power: 0 climbnorth is on a distinguished road
Look at this page for using recv, should help:

http://www.opengroup.org/onlinepubs/...ions/recv.html

Realize that recv returns a value. That value is how many bytes were read.
So read until it stops receiving bytes. Remember, it returns negative if there was an error, so handle that too.

This operation will block- which means, it will hang your application. This is not so great if your application wants to do other stuff while waiting for this data. To solve, you should put this into a seperate thread (unless your app doesn't do anything until it gets the data- in which case its ok BUT if this is GUI app, use thread or GUI will hang).

Also, you shouldn't put the declaration of your pointer inside the loop.
Also, you should consider not new/delete over and over in the loop. Instead, write to a buffer and reallocate the size as needed. There is a function called realloc that can help.


--
climbnorth is offline   Reply With Quote
Old Oct 3rd, 2006, 10:18 AM   #4
sarumont
Hobbyist Programmer
 
sarumont's Avatar
 
Join Date: Apr 2004
Location: /dev/urandom
Posts: 154
Rep Power: 5 sarumont is on a distinguished road
Send a message via ICQ to sarumont Send a message via AIM to sarumont Send a message via Yahoo to sarumont
Quote:
Originally Posted by climbnorth View Post
Look at this page for using recv, should help:

http://www.opengroup.org/onlinepubs/...ions/recv.html

Realize that recv returns a value. That value is how many bytes were read.
So read until it stops receiving bytes. Remember, it returns negative if there was an error, so handle that too.
OP does have it only reading 1024 bytes at a time, but that can still be problematic for this reason. I would concur with climbnorth's suggestion of threading the recv(); alternatively, OP could use select() rather than recv() to set a timeout on the read.
__________________
"Time is an illusion. Lunchtime doubly so."
-the late, great Douglas Adams
sarumont is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python FTP Client Wrapper Sane Python 6 Jun 22nd, 2006 9:44 PM
Networkprogramming in Unix Xyhm C 2 Mar 18th, 2006 1:35 PM
help with sockets, having a client recieve data as well as send. cypherkronis Python 7 Jul 1st, 2005 5:59 PM
Try capturing client text crashed!? Kam C++ 0 May 19th, 2005 1:31 AM
Instant Messaging App Help AusTex C 0 Apr 27th, 2005 4:52 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:18 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC