Board index » delphi » Connection points and unreliable clients...

Connection points and unreliable clients...

Hi All,

I have a server that propagates events to it's connected clients. When one
(or more) of the clients terminate abnormally (perhaps with a power failure)
it causes the server to 'lock up'.

I think this is because the server thinks that the client is still connected
to it's interface and still attempts to send new events to it.

Am I correct in thinking this?
Is there a way to handle this situation elegantly?

Thanks

Joe Lippa

 

Re:Connection points and unreliable clients...


Quote
Joe Lippa <jli...@motherwellcs.com> wrote in message

news:3b053141$1_1@dnews...

Quote
> Hi All,

> I have a server that propagates events to it's connected clients. When one
> (or more) of the clients terminate abnormally (perhaps with a power
failure)
> it causes the server to 'lock up'.

> I think this is because the server thinks that the client is still
connected
> to it's interface and still attempts to send new events to it.

On my servers, I always check that the winSocketStream is assigned before
writing to it, just in case it has just gone away, (freed by departing,
disconnected TserverClientThread).  Just in case the WSS disappears between
the check and the write I've got a exception handler round it.  No problemo!
Client disappears, server tries to send data & either realises that the
ioStream is nil or finds out in the exception handler.  No crash.  No
lockup.   Be careful where you declare your WSS's though, if you put them in
the threads then, when a thread dies, it's WSS object location might just
get reallocated to something non-nil that points at your data areas!

Rgds,
Martin

Re:Connection points and unreliable clients...


Thanks for the reply Martin -

I think I have mislead you in my original post. I am not using sockets to
communicate - I am using DCOM Server events (connection points).

This is a small snippet of my code -

function TServerInt.GetEnumerator: IEnumConnections;
var
  Container: IConnectionPointContainer;
  ConnectionPoint: IConnectionPoint;
begin
  Result := nil;
  OleCheck(QueryInterface(IConnectionPointContainer, Container));
  OleCheck(Container.FindConnectionPoint(AutoFactory.EventIID,
ConnectionPoint));
  ConnectionPoint.EnumConnections(Result);
end;

procedure TServerInt.SendEvent;
var
  Enum: IEnumConnections;
  ConnectData: TConnectData;
  Fetched: Cardinal;
begin
  Enum := GetEnumerator;
  if (Enum <> nil) then
  begin
    while Enum.Next(1, ConnectData, @Fetched) = S_OK do
      if ConnectData.pUnk <> nil then
      begin
        (ConnectData.pUnk as IServerIntEvents).EventNotification;
        ConnectData.pUnk := nil;
      end;
  end;
end;

At no point do I create a socket. I do however enumerate the clients
connected to the Server's interface. I need a method of detecting which
clients are actually alive in this enumeration.

Any further ideas?

Thanks

Joe Lippa

Quote
Martin James <james...@nortelnetworks.com> wrote in message

news:3b08e284_1@dnews...
Quote

> Joe Lippa <jli...@motherwellcs.com> wrote in message
> news:3b053141$1_1@dnews...
> > Hi All,

> > I have a server that propagates events to it's connected clients. When
one
> > (or more) of the clients terminate abnormally (perhaps with a power
> failure)
> > it causes the server to 'lock up'.

> > I think this is because the server thinks that the client is still
> connected
> > to it's interface and still attempts to send new events to it.

> On my servers, I always check that the winSocketStream is assigned before
> writing to it, just in case it has just gone away, (freed by departing,
> disconnected TserverClientThread).  Just in case the WSS disappears
between
> the check and the write I've got a exception handler round it.  No
problemo!
> Client disappears, server tries to send data & either realises that the
> ioStream is nil or finds out in the exception handler.  No crash.  No
> lockup.   Be careful where you declare your WSS's though, if you put them
in
> the threads then, when a thread dies, it's WSS object location might just
> get reallocated to something non-nil that points at your data areas!

> Rgds,
> Martin

Re:Connection points and unreliable clients...


Quote
"Joe Lippa" <jli...@motherwellcs.com> wrote in message

news:3b053141$1_1@dnews...

Quote
> Hi All,

> I have a server that propagates events to it's connected clients. When one
> (or more) of the clients terminate abnormally (perhaps with a power
failure)
> it causes the server to 'lock up'.

> I think this is because the server thinks that the client is still
connected
> to it's interface and still attempts to send new events to it.

> Am I correct in thinking this?

Yes, the COM runtime gets delayed notification of abnormal disconnects.
There is a ping infrastructure and does a cleanup and it can take up to a
few minutes for DCOM to pick up dead interface pointers.

Quote
> Is there a way to handle this situation elegantly?

If you don't want the lock up, fire the events from a thread. Note you'll
need to understand and implement marshaling to do this.

--
have fun
Binh Ly
www.techvanguards.com

Re:Connection points and unreliable clients...


Quote
"Joe Lippa" <jli...@motherwellcs.com> wrote in message

news:3b0a39c5_2@dnews...
Quote
> Thanks for the response Binh -

> Do you know of any good examples of how to enumerate a server's connection
> points in a thread? I have attempted Marshalling as documented on your
tips
> page (4. Marshal interface pointers across apartments) without much

success.

Show your code and indicate what's wrong.

--
have fun
Binh Ly
www.techvanguards.com

Other Threads