Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IdHttp and Socket Error # 11004 issue

984 views
Skip to first unread message

Rafael

unread,
Jun 6, 2008, 9:33:02 AM6/6/08
to
Hey guys

Something odd is happening with the tidhttp component and I was wondering if
I can get some help here. I have a form with a button and a tidhttp
component. The onclick event is coded as bellow:

procedure TForm1.Button2Click(Sender: TObject);
var
vHtml : string;
begin
IdHTTP1.ProxyParams.BasicAuthentication := False;
IdHTTP1.Request.ContentLength := -1;
IdHTTP1.Request.Accept := 'text/html, */*';
IdHTTP1.Request.BasicAuthentication := true;
IdHTTP1.Request.UserAgent := 'Mozilla/3.0 (compatible; Indy Library)';
IdHTTP1.HTTPOptions := [hoForceEncodeParams];
IdHTTP1.Connect('http://www.google.com');
try
vHtml := IdHTTP1.Get('http://www.google.com');
finally
IdHTTP1.Disconnect(False);
end;
end;

When I click in button for the first time everything works fine, but when I
do a second click on the button I get the error:

---------------------------
Debugger Exception Notification
---------------------------
Project HttpConnIndy.exe raised exception class EIdSocketError with message
'Socket Error # 11004
'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------

What's going on? If I close my project and run it again the error does not
happen. I guess that the disconnect method does not really disconnect the
socket. If I comment the line:

"IdHTTP1.Connect('http://www.google.com');"

everything works fine. I have debugged the source code of indy and I have
discovered that the method IdWinsock2.GetHostByName(PChar(AHostName)) in
IdStackWindows unit, at the second button click, dos not return an PHostEnt
(its nil).

I'm using indy 10.0.52


Remy Lebeau (TeamB)

unread,
Jun 6, 2008, 12:31:37 PM6/6/08
to

"Rafael" <tecno...@prolink.inf.br> wrote in message
news:4849...@newsgroups.borland.com...

> IdHTTP1.Request.ContentLength := -1;
<snip>
> IdHTTP1.Connect('http://www.google.com');
<snip>
> IdHTTP1.Disconnect(False);

Get rid of all of that. -1 is not a valid ContentLength value, and you
should not be calling Connect() manually. Get() does that internally for
you. Try this code instead:

procedure TForm1.Button2Click(Sender: TObject);
var
vHtml : string;
begin
IdHTTP1.ProxyParams.BasicAuthentication := False;

IdHTTP1.Request.Accept := 'text/html, */*';
IdHTTP1.Request.BasicAuthentication := true;
IdHTTP1.Request.UserAgent := 'Mozilla/3.0 (compatible; Indy
Library)';
IdHTTP1.HTTPOptions := [hoForceEncodeParams];

vHtml := IdHTTP1.Get('http://www.google.com');

end;

> I guess that the disconnect method does not really disconnect the socket.

Yes, it does.

> If I comment the line:
>
> "IdHTTP1.Connect('http://www.google.com');"
>
> everything works fine.

You should not have been calling Connect() to begin with.

> I have debugged the source code of indy and I have discovered
> that the method IdWinsock2.GetHostByName(PChar(AHostName)) in
> IdStackWindows unit, at the second button click, dos not return an
> PHostEnt (its nil).

Which means the OS itself, not Indy, is failing to resolve the specified
hostname. Which makes sense because 'http://www.google.com' is not a valid
hostname when establishing a socket connection. It is a URL that contains a
hostname which TIdHTTP extracts before calling Connect() internally. If you
are going to call Connect() manually in any componnet, do not specify
protocol information at all, ie:

Connect('www.google.com');

> I'm using indy 10.0.52

That is a VERY old version. You should consider upgrading.


Gambit


Rafael

unread,
Jun 6, 2008, 12:57:49 PM6/6/08
to
Hey Remy

OK .. thanks! I will not call connect at all. How can I do to get the newest
indy version? I just found svn snapshots, and I'm not interested to get an
developing version.

Rafael

"Remy Lebeau (TeamB)" <no....@no.spam.com> escreveu na mensagem
news:484966a1$3...@newsgroups.borland.com...

Rafael

unread,
Jun 6, 2008, 1:14:15 PM6/6/08
to
Nevermind. I just found it.

Thanks for all
Rafael

"Rafael" <tecno...@prolink.inf.br> escreveu na mensagem
news:4849...@newsgroups.borland.com...

Remy Lebeau (TeamB)

unread,
Jun 6, 2008, 2:03:49 PM6/6/08
to

"Rafael" <tecno...@prolink.inf.br> wrote in message
news:4849...@newsgroups.borland.com...

> How can I do to get the newest indy version? I just found svn snapshots

That is the latest version.

> I'm not interested to get an developing version.

Snapshots are the only versions available.


Gambit


0 new messages