Article View: borland.public.cppbuilder.internet.socket
Article #1240Re: Problem with recv
From: Eduardo Jauch
Date: Fri, 23 Feb 2007 00:56
Date: Fri, 23 Feb 2007 00:56
75 lines
3648 bytes
3648 bytes
Remy Lebeau (TeamB) escreveu:
> You are not exiting if the socket was not created.
>
That's because i'm only begining the code :)
There lot's of things yet to implement.
>> n = connect(sockfd, (struct sockaddr*)&addr, sizeof(addr));
>> printf("\nResposta de connect: %d", n);
>> if(n != 0) return 0;
>
> You are not calling closesocket() or WSACleanup() if connect() fails.
Again, even this been an error, I'm only doing some fast tests, not
doing the code to work "really" :)
> I do not recommend implementing the HTTP protocol manually. It is a
> very complex protocol. You really should stick with premade HTTP
> libraries/components that do all of the work for you.
I admit that implementing the HTTP protocol is very complex :)
But seens very funny no? ;)
I'm reading the documentation and this was the first thing I see.
But I'm not a "professional" C++ programmer. I really make some code and
some money with them, but is not my first activity.
So I really like to learning something knew :) Even something of this
complexity ;)
This was only a first try. :) I'm yet in the beginning of the lecture of
the documentation. :) I need learn much more about C++ too :)
> For example,
> you are missing a CRLF in the string above. In order for the server
> to know when the headers have ended, you must send a blank line after
> than, but you are not doing that.
Well... I really was thinking that the last '\r\n' was that... I don't
know that was necessary another... I'll try it :)
> You are not taking into account that send() can return less than the
> amount you asked it to send. You need to call send() in a loop until
> all data has been accepted.
You're right :) I see this on other forum too, but I was only trying to
"receive" some data... Not the entire page. :)
Also, you are sending the entire buffer
> (all 4000 bytes), not just the string data you copied into it. You
> should be using strlen() instead of sizeof().
>
I'm read on another forum exactly the oposite... Now I'm in doubt...
Sizeof will return 4000 to me...
If the buffer is empty (full of '\0'), strlen will return 4000 too? Not 0?
> You are not taking into account that recv() can return < 0. When that
> happen, you will be accessing memory outside of your buffer.
>
I forget this... :$ hehe
> That is because you are not terminating your HTTP request correctly,
> so the server never sends a reply at all, and recv() ends up timing
> out.
So, it's explained :)
I'll take all the tips and information seriously :)
This will help me much, I'm certain :)
Thank's Gambit :)
Technical Details
Message-ID:
<45de3b88@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45de060c$1@newsgroups.borland.com> <45de1497$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,f4676ab8bfe79c79 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 22 Feb 2007 22:56:22 -0200 From: Eduardo Jauch <eduardo.jauch@gmail.com> User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: Problem with recv References: <45de060c$1@newsgroups.borland.com> <45de1497$1@newsgroups.borland.com> In-Reply-To: <45de1497$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 201.89.14.159 Message-ID: <45de3b88@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1172192136 201.89.14.159 (22 Feb 2007 16:55:36 -0800) Lines: 75 Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail