lNet HTTP Put for upload files to server? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Shebuka · 2012-12-13 14:16 Hi all, i need to upload to server files of different size via HTTP Put, but in lhttp there is only hmHead, hmGet, hmPost and hmUnknown methods... Is there a way to do this with lNet? Alternatives? Thanks. ---------------------------------------------------------------------- Dibo · 2012-12-13 14:54 Yeah, LNet are fine but to much typed. Even HTTP statuses are typed so I had to add manually statuses for webservices. That's why I finally moved my project to synapse where I can do what I want. You can easily add PUT by opening lhttp.pp from lnet -> lib. Then: 1. Change this type: Code: [Select]TLHTTPMethod = (hmHead, hmGet, hmPost, hmUnknown); to: Code: [Select]TLHTTPMethod = (hmHead, hmGet, hmPost, hmPut, hmUnknown); 2. And this: Code: [Select]  HTTPMethodStrings: array[TLHTTPMethod] of string = ('HEAD', 'GET', 'POST', '');  to: Code: [Select]  HTTPMethodStrings: array[TLHTTPMethod] of string = ('HEAD', 'GET', 'POST', 'PUT', '');  3. Recompile / rebuild LNet package ---------------------------------------------------------------------- Dibo · 2012-12-13 14:59 And you probably will need hmDelete also. Oh, and try add new methods here too: Code: [Select]constructor TURIHandler.Create; begin   FMethods := [hmHead, hmGet, hmPost, hmPut]; end; ---------------------------------------------------------------------- Shebuka · 2012-12-13 15:48 Yes, also hmDelete is needed So it will work with this simple additions? Magic! ---------------------------------------------------------------------- Dibo · 2012-12-13 21:33 It should work, I used it in my project. Let me know if it work for you ---------------------------------------------------------------------- Shebuka · 2012-12-20 16:30 It's working I've used a piece of your code from here, that's working like a charm I've also added this code to TLHTTPClien: Code: [Select]        if FMethod = hmPut then         begin           FHttpClient.OnCanWrite := @MyCanWrite;           FHttpClient.ContentLength := FFileStream.Size;           FHttpClient.AddExtraHeader('User-Agent: Mozilla/3.0 (compatible)');           FHttpClient.AddExtraHeader('Content-Type: application/octet- stream');         end;      But I have a problem, FHttpClient is my THttpClient threaded class, it call FHttpClient.CallAction inside Execute and call Synchronize(@SynchronizeProgress); to tell me the progress and Synchronize(@SynchronizeDownloadReceive); when it has finished. The problem is if I open an OpenDialog (with .Execute) while FHttpClient is sending it doesn't send me Synchronize anymore! Edit: not only OpenDialog, whatever form that is of Dialog family... ---------------------------------------------------------------------- Dibo · 2012-12-20 18:41 Why you are using LNet in thread? LNet are designed for asynchrous usage, so they don't need threads (unlike synapse) ---------------------------------------------------------------------- Shebuka · 2012-12-20 22:53 Quote from: Dibo on December 20, 2012, 07:41:54 pmWhy you are using LNet in thread? LNet are designed for asynchrous usage, so they don't need threads (unlike synapse) I'm writing for Carbon so i can't use visual lNet and can only use the basic one. In basic I need to manually call .CallAction so i've created a small class based on thread that do this, when i call resume it create a lhttpclient, set all settings, events, headers, call .CallAction and periodically send me progress event to update my interface, when sending/receiving/request is done it sends me end event, close socket and suspend self. And i need 3 of them to make 2 parallel downloads and 1 upload. Maybe I can simplify it, any suggestion? ---------------------------------------------------------------------- Almindor · 2013-01-04 01:31 You should be fine with threads as long as you keep each separate. To keep ALL "lNets" in one thread just use one common eventer (create it before TLHTTP etc. and then assign to each) and use eventer.CallAction in the one main "networking" thread. This will ensure all callback event functions will be executed in the same thread as you do the callback. Everything else should be GUI- level synchronization, I can't help you there. The good news is, I have a mac book pro now. The bad news is I don't have much time to write the carbon/cocoa "link" to sockets event watching mechanisms so I can extend lNet for the widgetset. ---------------------------------------------------------------------- Shebuka · 2013-01-07 10:31 Hi Almindor! Each of my THttpClient threader class has one LHttpClient, so yes, it's one per thread. My problem now is not really with lNet but with thread, it like simply stop working after any opened dialog! As soon as i open a dialog I put a breakpoint inside while not terminated loop and it's never reached neither with opened dialog neither after i dismiss that dialog! ---------------------------------------------------------------------- Almindor · 2013-01-19 01:46 Not sure if I understand correctly. You have X threads each with one lNEt client in it, but your main problem atm. is that those threads loops don't seem to be looping once you open an opengl dialog? Did I get it right? ---------------------------------------------------------------------- Shebuka · 2013-01-28 11:25 Quote from: Almindor on January 19, 2013, 02:46:15 amNot sure if I understand correctly. You have X threads each with one lNEt client in it, but your main problem atm. is that those threads loops don't seem to be looping once you open an opengl dialog? Did I get it right? Yes, you get it right it seems that it's waiting in a thread synchronize semaphore. http://bugs.freepascal.org/view.php?id=23601