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
votes
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.
TIdServerContextclass. - Victoria