Remy Lebeau (TeamB) escreveu:
Quote
Oh yes, you most certainly do!!!! That is the ONLY way to use HTTP
properly. If you do not follow the rules, even the slightlest changes
to the HTML could cause your code to fail very very badly. You MUST
use the sizes and types that the server actually specifies. This is
EXTREMELY important if you ever want to use keep-alives properly as
well, as you don't want to leave unfinished data in the socket buffers
between requests.
Seriously, the more you push forward on this topic, the more I see how
wrongly you are implementing everything. You really should consider
using pre-made libraries for everything. If you want portability, you
should look at libcurl (curl.haxx.se) and other cross-platform
libraries.
You not understand Remy. But this is my fault.
This app that I'm doing, is for my personal use only.
I don't mind if a change on the page that I access will make me re-write
the code. I'll I mind is to put a code to verify if any changes that
affect the behaviour of the program have been done. So, when I start the
app, it will check if the pages are ok. If not, I'll use some other app
(like Ethereal you mentioned) to find the changes that have been made.
Of course, I'll use many of your knowledge to better my program.
Quote
>The page that agendar_recv() access (look to my other post),
>always return a chunked page.
You are most certainly NOT handling HTTP chunked data at all !! You
are not even looking at the "Transfer-Encoding" header, which tells
you whether the data is chunked or not in the first place. If it is
NOT chunked, then you must use the "Content-Length" header to know how
many bytes to read.
I sow every header of the pages that I access to see if it was chunked
or not, to make the code without the need to verify this every time I
access the page. Is bad programing, but will work until they change the
page, and no ptoblem with that :)
Quote
>So, I read the buffer until I get the final like this: "0\r\n\r\n"
tnat
>indicates the end of the response (according with RFC2616)
You are not even close to implementing what the RFC says to do in
regards to handling chunked data.
Of course not!
To do this, I will have to write praticaly a new "component" to handle
http. This isn't my goal.
Quote
>And it works.
Only because you are completely ignoring everything.
Yes... :)
But works :)
Quote
>If I try to read anything after this, the recv stay many seconds
>waiting fod data and finaly return 0.
As it should be, because there is no data sent after the final chunk
block. You need to stop reading after you receive that block. But
you are not stopping, because you are not handling chunked reading
correctly to begin with.
Oh...
But I'm stopping :)
If you look at the code, you'll see this:
recv_buffer[bytes] = '\0';
ptr_recv = &recv_buffer[bytes - 5];
strcat(html, recv_buffer);
if(strcmp(ptr_recv, "0\r\n\r\n") == 0)
break;
}
This is at the end of the loop of the recv.
The last line "if(strcmp" is exactly verifying if the chunked block is
the last (because this page is chunked)
Quote
>Then, I understand correct the bcb 6 help :)
No, you don't understand, not even close. The code you have shown so
far demonstrates that. You are FAR away from having a working HTTP
implementation.
HUm... Really I need learning much more :)
But anyway, besides the fact that EXACTLY every 91 requests the server
close the connection, fact that I will pursue to know if is an error of
my code or is the behaviour of the server, besides this, my app is
working perfectly, returning the results I need :)
Quote
>At each 91 requests, the server close the connection... :)
<snip>
>Say that to the server. Look's like he don't know that ;)
More like you don't know how to use sockets correctly in the first
place. Your code is very very wrong for what you are attempting to
do. You seriously need to clean it up ALOT just to get the basic TCP
functionality working correctly, let alone the HTTP functionality on
top of it.
Please, don't say that :)
I'm not really trying to do a BIG app. Much less an HTTP app. Only use
sockets to do some few tasks.
I have done some changes in code, particularly with the cookies. My code
works very well :) But was misplaced. Now is out of the recv loop, so,
when the recv is successful, I get new cookies.
Of corse I'll change the code a lot. I know I must learn much. :)
But you help me much too.
For exemple, my code now take in mean 0.55 seconds to read, interpret,
find, and store the information I seek on the page :)
The last version (that uses WinHTTP) take 0.65 seconds.
On the end of day, My new code (that I'm certain have much to improve)
access thousands more times the page that the predecessor :)
Thanks :)
{smallsort}