开发者

Delphi IdMappedPortTCP Question

Is 开发者_StackOverflow社区there a way to disconnect an active connection? I know with OnConnect you can reject connections...but thats only when there connecting


Yes, the TidMappedPortTCP is a TidTCPServer descendant, so you can basically use a few different approaches to disconnect active clients. For example, if you want to disconnect an active client inside the OnExecute event (based on some arbitrary criteria) you can simply do this somewhere inside the event handler:

AContext.Connection.Disconnect;

If you need to disconnect an active connection somewhere else in your code (eg. not in the OnExecute event handler), the approach would be something like this:

  • Create a list (TList or some collection class) which will hold your active connections;
  • Inside OnConnect event handler, add any new clients to this list;
  • Inside OnDisconnect event handler, remove disconnected clients from this list;

This way you will always have a collection of active clients which will enable you to find a specific client, access it's connection object and call the Disconnect method when needed.

Let me know if you need more detailed code sample.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜