Jump to content
GG2023

Can I use TsslWebSocketCli in a thread?

Recommended Posts

I was told the component uses message pump so guess the answer is no.

 

I am having Thread handle is invalid (6) when I create this object in thread's constructor.

 

The application is a service, so no forms and no messaging.

 

Thanks.

Share this post


Link to post

ICS components are widely used in Windows Services, less often in threads, really two different questions.  

 

For Windows Services, a VCL service project with SvcMgr gives you a form onto which to drop your components, and provides a message pump so they work just as if it is a GUI. 

 

ICS has a sample IcsAppMon;,dpr which has a WebSocket server component running as a Windows Service, although it uses the DDSvcMgr version ofSvcMgr which allows the application to be run as both a GUI or installed as a Windows Service, makes development and debugging much easier.  Using the WebSocket Client would be no different, that is used in the sample IcsAppMonMan which talks to the server, but is only a GUI since it talks to multiple servers.  

 

Not sure why, but we don't seem to currently have any simple Windows Service samples, guess I need to add one for the next release.  

 

Angus

 

Share this post


Link to post
6 hours ago, GG2023 said:

I am having Thread handle is invalid (6) when I create this object in thread's constructor.

When you want to use the object inside a thread, then you should create it inside the thread - the constructor still runs in the main thread!

Share this post


Link to post

Well the socket is now being created without exceptions, but OnWSFrameRcvd never gets fired.

 

I create the socket with NIL as an Owner. Should I somehow reference service's main DM in order to get message pump to work?

 

Thanks.

Share this post


Link to post

Well the socket is now being created without exceptions, but OnWSFrameRcvd never gets fired.

 

I create the socket with NIL as an Owner. Should I somehow reference service's main DM in order to get message pump to work?

 

Thanks.

Share this post


Link to post

You have not explained your environment, but assuming this is a Windows Service, you should have the message loop in the ServiceExecute event:

 

procedure TIcsTcpServce.ServiceExecute(Sender: TService);
begin
    while not Terminated do
        ServiceThread.ProcessRequests(TRUE);
end;

 

So there is only one thread for the main unit, just like most GUIs.  

 

Angus

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×