[英]How to start Indy TCP Server with parameters?
I am building a TCP Server using Indy 10 (from Delphi 2009). 我正在使用Indy 10(来自Delphi 2009)构建TCP服务器。 In OnExecute event I need to acces some data from the main thread.
在OnExecute事件中,我需要从主线程访问一些数据。 It is possible to pass that data to the server thread when I start it ?
我启动它时可以将该数据传递给服务器线程吗? The server is started with
IdTCPServer1.Active:=True;
服务器以
IdTCPServer1.Active:=True;
启动IdTCPServer1.Active:=True;
so I don't see how I can pass some parameters. 所以我不知道如何传递一些参数。
It is not possible to pass extra parameters to TIdTCPServer
. 无法将额外参数传递给
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. 要跟踪事件中的每个连接数据,可以使用
TIdContext.Data
属性,或从TIdServerContext
派生自定义类并将其分配给TIdTCPServer.ContextClass
属性。 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. 例如,您的
OnConnect
事件处理程序可以使用TIdSync
或TThread.Synchronize()
从主线程检索最新数据,然后将其缓存在OnExecute
要使用的上下文中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.