[SOLVED][LNET] httpclient hangs on connection error lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- vexal · 2011-04-01 11:31 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 ? ---------------------------------------------------------------------- Dibo · 2011-04-01 12:25 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 · 2011-04-01 13:30 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 ---------------------------------------------------------------------- vexal · 2011-04-01 13:40 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 · 2011-04-01 16:40 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 · 2011-04-04 08:18 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. ---------------------------------------------------------------------- Almindor · 2011-04-04 10:54 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 · 2011-04-04 13:33 Thank you Almindor2 !