Recent

Author Topic: [SOLVED][LNET] httpclient hangs on connection error  (Read 9479 times)

vexal

  • New Member
  • *
  • Posts: 29
[SOLVED][LNET] httpclient hangs on connection error
« on: April 01, 2011, 01:31:58 pm »
Hi !

I'm using lnet (0.6.5) http client and it works well for an existing address.
But if i try to connect to a wrong address (ex: http://lalaru )
it hangs forever just after the OnError event.
This event told me this : "Error on connect: connection refused"
I see it stay forever in the TLTcp.CallAction loop
Do you know why ?
Do i need to do something in the onError event ?
« Last Edit: April 04, 2011, 10:36:54 am by vexal »

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: [LNET] httpclient hangs on connection error
« Reply #1 on: April 01, 2011, 02:25:58 pm »
What do you mean by "hangs forever"? In HTTP demo ASocket.Disconnect is call on error event. Try this.

P.S. I notify that lHTTP client "hangs forever" (no events fired even OnError) when server return HTTP status which component doesn't know. Look at unit /lnet/lib/lhttp.pp. Find const "HTTPStatusCodes". If server return status which not exist in this array then components hangs. You must then use some sniffer to see which status is returned and then add his number to this array. You must recompile lNet package after all. Disadvantage of lHTTP client is that it is too much "typed". If you don't need non-blocking socket then you can use synapse instead of lnet.

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
Re: [LNET] httpclient hangs on connection error
« Reply #2 on: April 01, 2011, 03:30:08 pm »
Do you mean that the CallAction call never returns after a OnError event?

Does this happen with a lNet example code or only your code? Can you provide an example please?

Thanks
« Last Edit: April 01, 2011, 03:34:19 pm by Almindor2 »

vexal

  • New Member
  • *
  • Posts: 29
Re: [LNET] httpclient hangs on connection error
« Reply #3 on: April 01, 2011, 03:40:31 pm »
Thank you.

When i say it "hangs forever" i mean the TLTcp.CallAction loops forever like if it is waiting for another event.
If i write ASocket.Disconnect; it change nothing.

I think it is because the address i tried is not valid. If i go to a valid address (but which do not exists) it works as expected.
I'm looking for a way to valid url but i did not find it for the moment.

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
Re: [LNET] httpclient hangs on connection error
« Reply #4 on: April 01, 2011, 06:40:34 pm »
Well that's actually OK. If your one socket gets disconnected (or never connects like in your case) you shouldn't continue doing the CallAction loop unless there's another connection you need etc.

Of course if it "hangs" somewhere that's a different story.

vexal

  • New Member
  • *
  • Posts: 29
Re: [LNET] httpclient hangs on connection error
« Reply #5 on: April 04, 2011, 10:18:20 am »
Thank you. sorry i just see now your first post.
If i try a malformed address (ex:  http://lalaru/mlkj.php ) with the example (fpget), i'm experiencing the same problem :
Code: [Select]
D:\devel\FreePascal\test>project1.exe http://lalaru/mlkj.php
Host: lalaru URI: /mlkj.php Port: 80
Error: Error on connect: connection refused
^C (after a while i stopped the program)
D:\devel\FreePascal\test>

How can i know if i am connected ?

I solved the problem by stopping my callaction loop if i get an error in the onerror event.
« Last Edit: April 04, 2011, 10:25:25 am by vexal »

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
Re: [SOLVED][LNET] httpclient hangs on connection error
« Reply #6 on: April 04, 2011, 12:54:51 pm »
For your case, you can either check for ssConnected and ssConnecting, or simply watch OnError and OnConnect events.

OnError will trigger when there's a problem with connecting to the server (like your case with bad address), OnConnect will trigger only when you successfully established the connection.

Using the TLSocket.SocketState is a bit more advanced, but you shouldn't need to use them.

Hope this helps.

vexal

  • New Member
  • *
  • Posts: 29
Re: [SOLVED][LNET] httpclient hangs on connection error
« Reply #7 on: April 04, 2011, 03:33:54 pm »
Thank you Almindor2 !  :)

 

TinyPortal © 2005-2018