1
votes

I am building a TCP Server using Indy 10 (from Delphi 2009). In OnExecute event I need to acces some data from the main thread. It is possible to pass that data to the server thread when I start it ? The server is started with IdTCPServer1.Active:=True; so I don't see how I can pass some parameters.

1
If the data changes and you want to make a snapshot, copy them and their reference pass e.g. through the custom TIdServerContext class. - Victoria
I don't have that class in my Delphi 2009. I searched for it. - Marus Gradinaru
Unit IdCustomTCPServer. But it might not be necessary. What are the data you want to pass to the execution thread? What are the data types? Do they change when the server is running? - Victoria
The data is the password for autentication, and yes, it can change in time. - Marus Gradinaru
That's a good task for multi read/exclusive write lock. - Victoria

1 Answers

3
votes

It is not possible to pass extra parameters to TIdTCPServer. Your server event handlers will have to retrieve the data from the main thread when needed.

To keep track of per-connection data across events, you can use the TIdContext.Data property, or derive a custom class from TIdServerContext and assign it to the TIdTCPServer.ContextClass property. For instance, your OnConnect event handler can retrieve the latest data from the main thread using TIdSync or TThread.Synchronize(), and then cache it in the context for OnExecute to use.