TScHttpWebRequest vs disconnect

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
DmitriNL
Posts: 15
Joined: Fri 26 Nov 2010 15:47

TScHttpWebRequest vs disconnect

Post by DmitriNL » Thu 16 Apr 2020 10:56

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.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: TScHttpWebRequest vs disconnect

Post by ViktorV » Fri 17 Apr 2020 13:00

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.

DmitriNL
Posts: 15
Joined: Fri 26 Nov 2010 15:47

Re: TScHttpWebRequest vs disconnect

Post by DmitriNL » Sat 18 Apr 2020 12:44

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.

DmitriNL
Posts: 15
Joined: Fri 26 Nov 2010 15:47

Re: TScHttpWebRequest vs disconnect

Post by DmitriNL » Sun 19 Apr 2020 05:42

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.
Last edited by DmitriNL on Sun 19 Apr 2020 16:52, edited 1 time in total.

DmitriNL
Posts: 15
Joined: Fri 26 Nov 2010 15:47

Re: TScHttpWebRequest vs disconnect

Post by DmitriNL » Sun 19 Apr 2020 16:45

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!

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: TScHttpWebRequest vs disconnect

Post by ViktorV » Tue 21 Apr 2020 14:23

We aim to optimize performance of our products during the development phase, thus we cannot give you any special recommendations to increase perfomance.

DmitriNL
Posts: 15
Joined: Fri 26 Nov 2010 15:47

Re: TScHttpWebRequest vs disconnect

Post by DmitriNL » Wed 22 Apr 2020 16:24

Thank you for your support.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: TScHttpWebRequest vs disconnect

Post by ViktorV » Fri 24 Apr 2020 10:03

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.

Post Reply