TIdHTTP and iphone

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Post Reply
Lena
BCBJ Master
BCBJ Master
Posts: 696
Joined: Sun Feb 06, 2011 1:28 pm

TIdHTTP and iphone

Post by Lena »

Hi.
I use this code in ComboBoxChange for download INI file:

Code: Select all

String path = L"http://nsnllc.um.la/states/" + ComboBoxState->Selected->Text + L".ini";
	 std::unique_ptr<TMemoryStream> StateINI(new TMemoryStream());
	 try
	  {
	   IdHTTP1->Get(path, StateINI.get());
	  }
	  catch(...)
		  {
		   ShowMessage(L"Error");
		   return;
		  }
*****
Everything works perfectly. However, a problem was found.
1. Start app on ihone. App works good.
2. I leave the application on the screen.
3. Putting my phone to sleep.
4. I wake up the phone.
5. Try ComboBoxChange and I see ShowMessage(L"Error");
If full restart app all good again.

I want to try to use the following code instead of the component IdHTTP1:
std::unique_ptr<TIdHTTP> MyIdHTTP(new TIdHTTP());

I cannot test my theory yet. I don't have a debug Мас right now.
What is your opinion on this issue?
Thanks.
Lena
BCBJ Master
BCBJ Master
Posts: 696
Joined: Sun Feb 06, 2011 1:28 pm

Re: TIdHTTP and iphone

Post by Lena »

Yes. After changing the code, the problem disappeared.

Code: Select all

try
	  {
	   std::unique_ptr<TIdHTTP> MyIdHTTP(new TIdHTTP());
	   MyIdHTTP->Get(path, StateINI.get());

	   //IdHTTP1->Get(path, StateINI.get());
	  }
rlebeau
BCBJ Author
BCBJ Author
Posts: 1716
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA
Contact:

Re: TIdHTTP and iphone

Post by rlebeau »

Lena wrote: 4. I wake up the phone.
5. Try ComboBoxChange and I see ShowMessage(L"Error");
I can't answer that without seeing the actual exception that you are catching. You are discarding all useful diagnostic information by using catch(...). Use catch(const Exception &e) instead, and then you can report the e.ClassName and e.Message strings. And if e.InnerException is not nullptr then you can iterate that linked-list of chained exceptions reporting their ClassNames and Messages as well.
Remy Lebeau (TeamB)
Lebeau Software
Lena
BCBJ Master
BCBJ Master
Posts: 696
Joined: Sun Feb 06, 2011 1:28 pm

Re: TIdHTTP and iphone

Post by Lena »

I see:
First chance exception at $00000001019CE574. Exception class EIdSocketError with message
'Socket Error # 57
Socket is not connected.'.
rlebeau
BCBJ Author
BCBJ Author
Posts: 1716
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA
Contact:

Re: TIdHTTP and iphone

Post by rlebeau »

Lena wrote:I see:
First chance exception at $00000001019CE574. Exception class EIdSocketError with message
'Socket Error # 57
Socket is not connected.'.
iOS is killing your active socket when the app is put to sleep or goes into the background. Searching around, this seems to be normal behavior for iOS, as sleeping/background apps are simply not allowed to maintain a persistent network connection, unless they are registered as VoIP apps.

So, you will just have to Disconnect() the TIdHTTP object each time you want to reuse it (or at least when the error occurs), or turn off HTTP keep-alives (set IdHTTP1->Request->Connection="close") if you are using HTTP 1.1. Or, just recreate the TIdHTTP object each time, as you have already discovered.
Remy Lebeau (TeamB)
Lebeau Software
Lena
BCBJ Master
BCBJ Master
Posts: 696
Joined: Sun Feb 06, 2011 1:28 pm

Re: TIdHTTP and iphone

Post by Lena »

Thank you very much!
Post Reply