Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-29 Thread Wilfried Mestdagh
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 r

Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-29 Thread Paul Read - nSolve Ltd
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 derv

Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-29 Thread 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

Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-28 Thread Paul Read - nSolve Ltd
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

Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-28 Thread Wilfried Mestdagh
It is the same. Write your application in a TObject. The only thing you have to create in your console application is that object. And when you use this object in a NT Service the only thing you have to create there is the same object. Message pump in NT Service is even more simply. You can do

Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-28 Thread Paul Read - nSolve Ltd
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)

Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-28 Thread Angus Robertson - Magenta Systems Ltd
> 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 t

Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-28 Thread Angus Robertson - Magenta Systems Ltd
> 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 s

Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-28 Thread Paul Read - nSolve Ltd
Do you recommend this procedure for a MS-Windows service? It seems a bit of a strange concept to me -- Regards Paul Read Partner Follow us: @nSolve *nSolve Ltd* 33-35 Daws Lane London NW7 4SD England www.nsolve.com Tel: +44 (0) 1993 40

Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-28 Thread Paul Read - nSolve Ltd
Thanks Angus for the quick reply 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 And the next time I try to Send and therefore the next time I run the MessageLo

Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-28 Thread Angus Robertson - Magenta Systems 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

Re: [twsocket] How to keep SslWSocket open in a multi-threaded console app?

2015-07-28 Thread Wilfried Mestdagh
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