Thread View: borland.public.cppbuilder.internet.socket
3 messages
3 total messages
Started by Naresh Chandran
Tue, 07 Jun 2005 19:44
TServerSocket and Windows Services
Author: Naresh Chandran
Date: Tue, 07 Jun 2005 19:44
Date: Tue, 07 Jun 2005 19:44
44 lines
2825 bytes
2825 bytes
Hi, I have an application that uses TServerSocket. The TServerSocket is created dynamically, and the connect, disconnect and read methods are attached to __published methods of a TDataModule object, at runtime. This works fine when run interactively: I have a form with a button, whose onclick calls a global method (startServer) which creates the TServerSocket dynamically (maintained in a global TServerSocket*, after being created by new TServerSocket(NULL)), assigns the serverType (non-blocking) and the event handlers, and opens the socket (->Open()). Once the server is thus started, the functionality in the OnClientRead method is available to TCP clients connecting/communicating with the server, and all three events, namely OnClientConnect, OnClientDisconnect and OnClientRead write to the log file. Currently, I am trying to convert this application into a Windows Service. In this case, I do not create the form with the button on it, and instead create only the TDataModule with the event handlers, and on service startup, call the global method (startServer) that sets the server listening. I can see that the server is listening on the specified port through netstat, once I start the service; But apparently, none of the TServerSocket events are triggered when a client connects, writes to the connection or disconnects, since none of the log file entries expected from these methods are writte to the file. From the client end, it is possible to establish a connection, write to it and close it; but when an attempt is made to read, the client hangs up, and does not return until the service is stopped, at which time the TServerSocket->Close() is called and the server is stopped. Is there any reason for VCL component events to not fire when run as a windows service ? Thanks, Naresh.
Re: TServerSocket and Windows Services
Author: Remy Lebeau (TeamB)
Date: Tue, 07 Jun 2005 20:27
Date: Tue, 07 Jun 2005 20:27
19 lines
1658 bytes
1658 bytes
"Naresh Chandran" <naresh@sentori.com> wrote in message news:42a5f86a$1@newsgroups.borland.com... > Currently, I am trying to convert this application into a Windows > Service. <snip> > none of the TServerSocket events are triggered when a client > connects, writes to the connection or disconnects Borland's TService architecture is multi-threaded. Non-blocking sockets require a message queue, but individual TService instances do not have a message queue by default. You would need to either 1) use the TService::OnExecute event to run your own message queue (I would not recommend this), or 2) use your TServerSocket in blocking mode instead so that a message queue is no longer needed. Gambit
Re: TServerSocket and Windows Services
Author: Naresh Chandran
Date: Wed, 08 Jun 2005 14:57
Date: Wed, 08 Jun 2005 14:57
12 lines
1440 bytes
1440 bytes
Hi, Thanks for the advice. I use Borland C++ Builder 3 (I guess TService is Builder 4 and above), although I have a feeling using the TServerSocket in blocking mode would solve my probem anyway. I have resisted from using blocking mode before due to the perceived complexity of coding for a multi-threaded application. Right now it appears to be the best solution to my situation. Thanks again, Naresh.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads