开发者

Maintaining list of connectionid for ipWorks TipwIPDaemon component

I have a server application built using the TipwIPDaemon component. When client开发者_StackOverflows connect the connected event is fired with the connectionid of the connection:

procedure TServLogic.IPDaemon1Connected(Sender: TObject; 
  ConnectionId, StatusCode: Integer; const Description: String);

The documentation states the TipwIPDaemon.connectioncount property returns the number of connections.

I was under the impression you would proceed as follows:

for i:=0 to ipd.connectioncount-1 do begin
  remotehost := ipd.remotehost[i]
  ......

However, I am now finding this is not the case, and for calls such as ipd.remotehost[x] the subscript x represents a unique connectionid.

So for example say I get my first connection. From what I have learned this this is always connectionid=1. If a 2nd connection comes in and afterward the 1st is dropped, references for the 2nd connection are still ipd.remotehosts[2]

My question: Is there any internal list of the connection id which correspond to the conectioncount? Or do I have to maintain this myself? Say for example I want to send data to all connected clients. I seem to need a "list" of the connectionid:

for i:=0 to ipd.connectioncount-1 do begin
  IPD.DataToSend[GetConnectionID(i)] := 'Hello There';
  ......


One way to do this is to use the Connected and Disconnected events. Basically you would maintain your own list of current connection IDs. When the Connected event fires you'd add the ID to your list. When the Disconnected event fires you'd remove that ID from your list.


Would you be okay with checking the status of each connection? For example, you should be able to do something like this:

for i:=0 to ipd.connectioncount-1 do
begin
  if (ipd.Connected[i]) then
  begin
    ipd.DataToSend[i] := 'Hello There';
    ...
  end;
end;      
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜