Keep alive connection in Delphi 5 - WeOnlyDo Discussion board

Keep alive connection in Delphi 5 (General questions)

by Michal, Monday, February 04, 2008, 15:27 (6137 days ago)

Hi,
I am not able to keep connection alive.
1. attempt:
wodHttp1.Blocking := True;
wodHttp1.URL := 'http://www.weonlydo.com';
wod1.KeepAlive := 1;
wod1.Get;
// here events Connected, Done, Disconnected are fired
// so the connection is closed

2. attempt:
wodHttp1.Blocking := True;
wodHttp1.URL := 'http://www.weonlydo.com';
wod1.KeepAlive := 1;
wod1.Connect;
// nothing happens here

3. attempt:
wodHttp1.Blocking := True;
wodHttp1.URL := 'http://www.weonlydo.com';
wod1.KeepAlive := 1;
wod1.Connect1;
// (this method is not documented) the events Connected is fired
// but now I don't know how to send a message by GET or POST?
// if I call wod1.Get after wod1.Connect1 the connection is closed.


Thanks,
Michal

Re: Keep alive connection in Delphi 5

by woddrazen, Monday, February 04, 2008, 15:55 (6137 days ago) @ Michal

Hi Michal,


You need to use Post Method to post something to server. So you should use your first example with Get and put Post after Get line. That should work without worry that wodHttpDLX will disconnect from server and will not be able to communicate any more.

KeepAlive is be default set to Automatic and you probably don't need to change it's value.

To see what is received, you can use HttpRespone Body Property.

More help for HttpResponse Body Property you can find here:
http://www.weonlydo.com/HttpDLX/Help/wodHttpDLXLib~HttpResponse~Body.html

wodHttpDLX Connect Method is Delphi is change to Connect1 because Delphi uses Connect for some internal operation.

You are using wod1 and wodHttp1 wodHttpDLX reference. You need to use just one reference because this is two different object and they cannot work together as one.

Let us know how it goes.


Regards,
Drazen

Re: Keep alive connection in Delphi 5

by Michal, Monday, February 04, 2008, 16:19 (6136 days ago) @ woddrazen

So I tried this:

wod1.Blocking := True;
wod1.URL := 'http://www.weonlydo.com';
wod1.KeepAlive := 1; // only for sure
wod1.Connect1; // here the event Connection was fired - it's OK
wod1.Get; // here the events Done and Disconnected were fired

So wod1.Get closed the connection - I don't want to close the connection.

Re: Keep alive connection in Delphi 5

by wodDamir, Monday, February 04, 2008, 16:47 (6136 days ago) @ Michal

Hi Miachal,

You also need to set HTTPVersion property to HTTP/1.1 . This is required since keep-alives are introduced in v1.1 of HTTP Protocol.

After that the connection should remain open after any request is made.

Regards,
Damba

Re: Keep alive connection in Delphi 5

by Michal, Monday, February 04, 2008, 17:02 (6136 days ago) @ wodDamir

Now I have:

wod1.Blocking := True;
wod1.URL := 'http://www.weonlydo.com';
wod1.KeepAlive := 1; // only for sure
wod1.HTTPVersion:='HTTP/1.1';
wod1.Connect1; // here the event Connection was fired - it's OK
wod1.Get; // here the events Done and Disconnected were fired

The result is the same - the connection is closed.

Re: Keep alive connection in Delphi 5

by wodDamir, Monday, February 04, 2008, 17:22 (6136 days ago) @ Michal

Michal,

I've just checked. The following code:

[code] wodHttpDLXCom1.Hostname := 'www.weonlydo.com';
wodHttpDLXCom1.HTTPversion := 'HTTP/1.1';
wodHttpDLXCom1.Blocking := true;
wodHttpDLXCom1.KeepAlive := 1;
wodHttpDLXCom1.Connect1;
wodHttpDLXCom1.Get;[/code]

remains connected to server. You can verify that by checking the component State property. Something like this:

[code]label1.Caption := wodHttpDLXCom1.StateString(wodHttpDLXCom1.State);[/code]

Can you try that?

Regards,
Damba

Re: Keep alive connection in Delphi 5

by Michal, Monday, February 04, 2008, 17:35 (6136 days ago) @ wodDamir

I tried:
wod1.Blocking := True;
wod1.URL := 'http://www.weonlydo.com';
wod1.KeepAlive := 1; // only for sure
wod1.HTTPVersion:='HTTP/1.1';
wod1.Connect1; // here the event Connection was fired - it's OK
State := Ord(wod1.State); // here State is 2 - Connected - idle.
wod1.Get; // here the events Done and Disconnected were fired
State := Ord(wod1.State); // here State is 0 - Not connected.

Re: Keep alive connection in Delphi 5

by wodDamir, Monday, February 04, 2008, 17:46 (6136 days ago) @ Michal

Michal,

Can you please try Hostname property instead of URL?

Also, what version of the component are you using?

Regards,
Damba

Re: Keep alive connection in Delphi 5

by Michal, Tuesday, February 05, 2008, 12:04 (6136 days ago) @ wodDamir

I tried Hostname but the result is the same:

wod1.Blocking := True;
wod1.Hostname := 'www.weonlydo.com';
wod1.KeepAlive := 1; // only for sure
wod1.HTTPVersion:='HTTP/1.1';
wod1.Connect1; // here the event Connection was fired - it's OK
State := Ord(wod1.State); // here State is 2 - Connected - idle.
wod1.Get; // here the events Done and Disconnected were fired
State := Ord(wod1.State); // here State is 0 - Not connected.

Re: Keep alive connection in Delphi 5

by wodDamir, Tuesday, February 05, 2008, 12:15 (6136 days ago) @ Michal

Michal,

I can't really tell why it doesn't work on your side. I've tested the same code here, and the component does leave the connection open.

Perhaps you have some firewall which terminates the connection? Can you try disabling it (including windows firewall)?

Also, are you using Delphi 5 or Delphi 2005? Perhaps you could send us a sample to techsupport@weonlydo.com so I could like to run it on my side?

Regards,
Damba

Re: Keep alive connection in Delphi 5

by Michal, Tuesday, February 05, 2008, 16:29 (6135 days ago) @ wodDamir

Yes, you are right!
I was going through a proxy and it didn't keep connection alive.
When I tested without proxy it worked fine and connection was kept alive.
But what is really important is the line:
wod1.HTTPVersion:='HTTP/1.1';
It doesn't work without it.

Thank you very much for your prompt help!

Michal