Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Sep : Indy 9 - not detecting disconnect over VPN

www.cryer.info
Managed Newsgroup Archive

Indy 9 - not detecting disconnect over VPN

Subject:Indy 9 - not detecting disconnect over VPN
Posted by:user@domain.invalid
Date:Wed, 19 Sep 2007 11:04:58

Hello.

I have a client/server application that connects over a VPN.  When the
connection goes away, the writer to the socket detects the disconnect,
but the reader of the socket continues to wait for data.

I created a sample application that shows this behavior and can provide
it (if you tell me where to do so)

Basically, the client spawns a thread which connects to the server.  It
tells the server it is waiting for data and then reads the socket for
the amount of data, followed by a n reads of the socket to get the
specified data.  This sits in a while loop until the socket is disconnected.

If I run this locally, it works fine and detects the disconnect.

Here is the client thread execute routine.

procedure TClientPollThread.Execute;
var
   i, count : integer;
   s : string;
   InfoRec : PInfoRec;  //A record of three strings used with
                        //postThreadMessage()
begin
// client is a member of this thread class and is a TidTCPClient
    try
       if not Client.Connected then begin
       FrmSocketTest.ClientDebugLog('Client'+IntToStr(ClientNum)+':
'+'Attempting connection in poll thread');  // write to a file
         Client.Connect();
          Client.WriteLn('POLLREQUEST');
     end;

     while (not Terminated) and client.connected do begin
       s := '';
       // this will block until satisfied.
       Count := Client.readinteger;
       for i := 1 to count do
         s := s+Client.ReadChar;

       new(infoRec);
       infoRec.s0 := IntToStr(ClientNum);
       infoRec.s1 :=
Client.Host+':'+intToStr(Client.Port)+':'+IntToStr(Client.Socket.Binding.port);
       infoRec.s2 := 'message at :'+FormatDateTime('hh:mm:ss.zzz',Time);
       if not Win32Check(PostThreadMessage(mainThreadID,
GUI_MESSAGE_FROM_THREAD,
                         GMFT_CLIENT_CHANGE_CONNECTION_INFO,
LParam(infoRec))) then
         Dispose(infoRec);
     end;
   except
       on e: exception do
     begin
       FrmSocketTest.ClientDebugLog('Client'+IntToStr(ClientNum)+':
'+'Exception in Execute: '+e.Message);
     end;
   end;
   ExecuteComplete := true;
end;

Replies:

www.cryer.info
Managed Newsgroup Archive