tags:

views:

45

answers:

2

I have a server application built using the TipwIPDaemon component. When clients 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';
  ......
A: 

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;      
Scott W
+1  A: 

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.

Spencer
Thank you. So you need to manage the list yourself. I am porting this from Indy. And with Indy you can loop over all open connections through tcpserver.Contexts. Is there any reason why the IPWorks TipwIPDaemon component cannot maintain this list internally?
M Schenkel
It does maintain this list, just in a different way. See my answer to this question -- you simply use the Connected property of each connection to determine whether or not it is still active.
Scott W