Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?
Thanks Angus, in fact I likewise I have a simple switch at startup to decide whether I'm running in GUI or service mode, which I share below as a way of saying thanks to the 'list' as I did not take on-board the fact that the Svcmgr::Application-CreateForm call means the TService class is dervived from TObject item and that can have a TSslWSocket component on it without any manual message pumps (rather than creating a thread that then creates the SslWSocket): //--- WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { if(FindCmdLineSwitch(GUI)) { Forms::Application-Initialize(); Forms::Application-CreateForm(__classid(TfrmMain), frmMain); //(TfrmMain::OnShow then creates the TService based object Forms::Application-Run(); } else { if((!Svcmgr::Application-DelayInitialize) || (Svcmgr::Application-Installing())) { Svcmgr::Application-Initialize(); } Svcmgr::Application-CreateForm(__classid(some class dervived from TService), pService); Svcmgr::Application-Run(); } } Thanks to all -- Regards Paul Read Partner Follow us: @nSolve http://www.twitter.com/nSolve *nSolve Ltd* 33-35 Daws Lane London NW7 4SD England www.nsolve.com http://www.nsolve.com Tel: +44 (0) 1993 40 20 11 Tel(US): +1 617 273 2304 On 29/07/2015 08:15, Angus Robertson - Magenta Systems Ltd wrote: Should I be calling MessageLoop or ProcessMessages? Neither, Delphi windows services are message driven just like Windows applications. Most of my windows services are actually dual GUI/service, with a simple GUI that does not require any interaction when run as a service. This makes testing vastly easier, since the program can be run under the Delphi debugger and then installed as a Windows service once it's working. Originally I wrote a simple service starter application that runs a standard Windows application as a service (with a command argument) and waits for it to finish before stopping, and sends a message if told to stop. I still sell an application using this technique after 18 years. The second generation used the SvCom environment from: http://www.aldynsoftware.com/ which creates a single application that can be run as a service or GUI, just drop components on a form, jkust works, but it's commercial. For new applications I use DD Service Application Framework written by one of the ICS developers, but his web site seems to be down at the moment. I think it's on Code Central but search is useless and brings up thousands of results. Angus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?
Hi, I do it a little different but results are similar. I create my whole application in a single TObject. So this object can run in a GUI as a console application as a NTService. For console application just App.Create; and run a message pump, for NTService the same: create the object and run message pump. So whole debugging and testing is in the console application (or GUI as you wish) - if all is running OK, just recomile the Service and it's done. There is even no testing required with the Service because it is exacly the same object that is running. Met vriendelijke groeten, Wilfried Op 29-07-15 om 09:15 schreef Angus Robertson - Magenta Systems Ltd: Should I be calling MessageLoop or ProcessMessages? Neither, Delphi windows services are message driven just like Windows applications. Most of my windows services are actually dual GUI/service, with a simple GUI that does not require any interaction when run as a service. This makes testing vastly easier, since the program can be run under the Delphi debugger and then installed as a Windows service once it's working. Originally I wrote a simple service starter application that runs a standard Windows application as a service (with a command argument) and waits for it to finish before stopping, and sends a message if told to stop. I still sell an application using this technique after 18 years. The second generation used the SvCom environment from: http://www.aldynsoftware.com/ which creates a single application that can be run as a service or GUI, just drop components on a form, jkust works, but it's commercial. For new applications I use DD Service Application Framework written by one of the ICS developers, but his web site seems to be down at the moment. I think it's on Code Central but search is useless and brings up thousands of results. Angus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?
Should I be calling MessageLoop or ProcessMessages? Neither, Delphi windows services are message driven just like Windows applications. Most of my windows services are actually dual GUI/service, with a simple GUI that does not require any interaction when run as a service. This makes testing vastly easier, since the program can be run under the Delphi debugger and then installed as a Windows service once it's working. Originally I wrote a simple service starter application that runs a standard Windows application as a service (with a command argument) and waits for it to finish before stopping, and sends a message if told to stop. I still sell an application using this technique after 18 years. The second generation used the SvCom environment from: http://www.aldynsoftware.com/ which creates a single application that can be run as a service or GUI, just drop components on a form, jkust works, but it's commercial. For new applications I use DD Service Application Framework written by one of the ICS developers, but his web site seems to be down at the moment. I think it's on Code Central but search is useless and brings up thousands of results. Angus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?
Should I be calling MessageLoop or ProcessMessages? I now have a working (but horrible) solution: TService creates a thread to perform the main processing On the first event this thread creates a TSslWSocket (with MultiThreaded=false) and calls Connect At this point I must call *MessageLoop *(not ProcessMessages) to make the connection I then send some data At this point I must call *ProcessMessages *(not MessageLoop) to send the data After sending of the data I call WSocket-PostQuitMessage() so ProcessMessages exits and the thread can complete its event Thereafter on further events I then send some data At this point I must call ProcessMessages (not MessageLoop) to send the data After sending of the data I call WSocket-PostQuitMessage() so the thread can complete its work Note MessageLoop needed after Connect called, yet ProcessMessages needed after Send Works. But surely can't be right?? -- Regards Paul Read Partner Follow us: @nSolve http://www.twitter.com/nSolve *nSolve Ltd* 33-35 Daws Lane London NW7 4SD England www.nsolve.com http://www.nsolve.com Tel: +44 (0) 1993 40 20 11 Tel(US): +1 617 273 2304 On 28/07/2015 19:42, Paul Read - nSolve Ltd wrote: A MS-Windows service I'm doing the data send in the main thread of the service (there are no other threads) If I don't call the WSocket-PostQuitMesage then the MessageLoop runs for ever stopping my thread doing anything else. (If I don't call WSocket-MessageLoop nothing happens at all) -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?
In a console app's thread, I make a valid connection, I call SslWSocket-Send, followed by MessageLoop. Once I receive OnDataSent message I call SslWSocket-PostQuitMessage(); And the data is sent and the control returns to the thread - perfect. The second time I want to send data (without closing-reopening the connection - which is not allowed by Apple) the MessageLoop immediately returns as SetTerminated(TRUE) was called once the MessageLoop was exited in the previous send. *Question what is the correct way to use a SslWSocket to send data over a continuously open connection?* If I understand you correctly, you are exiting the thread after open and a single send, which will close the connection. You need to keep the thread running and send a message to it (or use a thread event to pick something up) to send the next block. Angus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?
In a console application the best practice (not only for TWSocket) is to create a hidden window and an associated message pump. For the rest your application is only a message loop. The program itself you can do in a separate object just as it is a forms application. No need to call MessageLoop or any other sequentinonal thing. Rgds, Wilfried Met vriendelijke groeten, Wilfried Op 28-07-15 om 18:05 schreef Paul Read - nSolve Ltd: In a console app's thread, I make a valid connection, I call SslWSocket-Send, followed by MessageLoop. Once I receive OnDataSent message I call SslWSocket-PostQuitMessage(); And the data is sent and the control returns to the thread - perfect. The second time I want to send data (without closing-reopening the connection - which is not allowed by Apple) the MessageLoop immediately returns as SetTerminated(TRUE) was called once the MessageLoop was exited in the previous send. *Question what is the correct way to use a SslWSocket to send data over a continuously open connection?* -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?
In fact I am not exiting the thread but I am calling: SslWSocket-PostQuitMessage(); to break out of the socket MessageLoop In doing so this sets the SslWSocket Terminated to true Don't call it then! I thought PostQuitMessage was to break a thread, it posts WM_QUIT which is generally the end of all processing. Angus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?
A MS-Windows service I'm doing the data send in the main thread of the service (there are no other threads) If I don't call the WSocket-PostQuitMesage then the MessageLoop runs for ever stopping my thread doing anything else. (If I don't call WSocket-MessageLoop nothing happens at all) -- Regards Paul Read Partner Follow us: @nSolve http://www.twitter.com/nSolve *nSolve Ltd* 33-35 Daws Lane London NW7 4SD England www.nsolve.com http://www.nsolve.com Tel: +44 (0) 1993 40 20 11 Tel(US): +1 617 273 2304 On 28/07/2015 19:31, Angus Robertson - Magenta Systems Ltd wrote: Do you recommend this procedure for a MS-Windows service? It seems a bit of a strange concept to me Are you writing a console application or a service? Threads are generally unnecessary for ICS, except for some blocking functions like ping or SQL and when using hundreds of sockets in the same application. Angus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be