Page 1 of 1
TScHttpWebRequest vs disconnect
Posted: Thu 16 Apr 2020 10:56
by DmitriNL
Hi,
I moved from Indy components to SecureBridge components. At the moment I try to setup a simple HTTP connection and retreive some data. After running my code (without the ''disconnect()' function), it is not possible to execute the same code multiple times. I receive an error message "
Project Project1.exe raised exception class HttpException with message 'The operation is not allowed when the request is executed'.". After adding 'disconnect()' to the end of the code, it is possible to execute the code multiple time. I am wondering if it is correct to call 'disconnect()'. Is there another way? Maybe to keep the connection open or alive?
Below you find my code.
Code: Select all
ScHttpWebRequest1->RequestUri = "https://my-url.com";
ScHttpWebRequest1->Method = rmGET;
TScHttpWebResponse *ScHttpWebResponse1 = ScHttpWebRequest1->GetResponse();
Memo1->Text = ScHttpWebResponse1->ReadAsString();
ScHttpWebRequest1->Disconnect();
Thank you in advance for your response.
Re: TScHttpWebRequest vs disconnect
Posted: Fri 17 Apr 2020 13:00
by ViktorV
To accomplish your task, you can use the property TScHttpWebRequest.ConnectionGroupNameConnectionGroupName
https://www.devart.com/sbridge/docs/tsc ... upname.htm. You'd have to call the Connect method in any case, yet with this property, the TCP connection won't be lost, and you'd be able to consquently send several requests through a single physical connection.
Re: TScHttpWebRequest vs disconnect
Posted: Sat 18 Apr 2020 12:44
by DmitriNL
Thank you for your answer. I tried your solution. I cannot notice any difference. Also your solution still needs to call 'disconnect()'.
Without using ConnectionGroupName
323 milliseconds
210 milliseconds
283 milliseconds
227 milliseconds
Code: Select all
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDateTime BeginTime = Now();
ScHttpWebRequest1->RequestUri = "https://my-url.com";
ScHttpWebRequest1->Method = rmGET;
TScHttpWebResponse *ScHttpWebResponse1 = ScHttpWebRequest1->GetResponse();
Memo1->Text = ScHttpWebResponse1->ReadAsString();
ScHttpWebRequest1->Disconnect();
TDateTime EndTime = Now();
int MilliSeconds = MilliSecondsBetween(EndTime, BeginTime);
Memo2->Lines->Add(IntToStr(MilliSeconds) + " milliseconds");
}
// ---------------------------------------------------------------------------
With using ConnectionGroupName
338 milliseconds
233 milliseconds
210 milliseconds
228 milliseconds
Code: Select all
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TDateTime BeginTime = Now();
ScHttpWebRequest1->RequestUri = "https://my-url.com";
ScHttpWebRequest1->Method = rmGET;
ScHttpWebRequest1->ConnectionGroupName = "test_group";
TScHttpWebResponse *ScHttpWebResponse1 = ScHttpWebRequest1->GetResponse();
Memo1->Text = ScHttpWebResponse1->ReadAsString();
ScHttpWebRequest1->Disconnect();
TDateTime EndTime = Now();
int MilliSeconds = MilliSecondsBetween(EndTime, BeginTime);
Memo2->Lines->Add(IntToStr(MilliSeconds) + " milliseconds");
}
// ---------------------------------------------------------------------------
I am comparing Indy IdHTTP with SecureBridge. It seems Indy is slower running for the first time using SSL. After the first time Indy seems much faster than SecureBridge. Probably I am doing something wrong. Can you please help me out? Thank you for your support.
Re: TScHttpWebRequest vs disconnect
Posted: Sun 19 Apr 2020 05:42
by DmitriNL
I the meantime I found a different method to get data over http using SecureBridge. (
viewtopic.php?t=36270) My solution below seems faster than my previous post.
With using ConnectionGroupName
308 milliseconds
144 milliseconds
148 milliseconds
140 milliseconds
Code: Select all
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDateTime BeginTime = Now();
TScHttpWebRequest *Request = new TScHttpWebRequest("https://my-url.com");
try
{
Request->Method = rmGET;
Request->ConnectionGroupName = "test_group";
TScHttpWebResponse *Response = Request->GetResponse();
try
{
String ResponseStr = Response->ReadAsString();
Memo1->Lines->Text = ResponseStr;
}
__finally
{
Response->Free();
}
}
__finally
{
Request->Free();
}
TDateTime EndTime = Now();
int MilliSeconds = MilliSecondsBetween(EndTime, BeginTime);
Memo2->Lines->Add(IntToStr(MilliSeconds) + " milliseconds");
}
//---------------------------------------------------------------------------
Indy IdHTTP download times are
508 milliseconds
131 milliseconds
123 milliseconds
133 milliseconds
Indy seems still slightly faster than SecureBridge. Are there more improvements I can make to get better results? Thank you in advance for your support.
Re: TScHttpWebRequest vs disconnect
Posted: Sun 19 Apr 2020 16:45
by DmitriNL
Instead of handling the response as text, handling the response as a stream improves performance. Download times of SecureBridge and Indy are almost equal. Indy is slower when calling data of HTTP the first time. Any advice regarding performance? Thank you!
Re: TScHttpWebRequest vs disconnect
Posted: Tue 21 Apr 2020 14:23
by ViktorV
We aim to optimize performance of our products during the development phase, thus we cannot give you any special recommendations to increase perfomance.
Re: TScHttpWebRequest vs disconnect
Posted: Wed 22 Apr 2020 16:24
by DmitriNL
Thank you for your support.
Re: TScHttpWebRequest vs disconnect
Posted: Fri 24 Apr 2020 10:03
by ViktorV
Thank you for the interest to our product.
If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.