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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.