Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Dec : Re: how to check connection?

www.cryer.info
Managed Newsgroup Archive

Re: how to check connection?

Subject:Re: how to check connection?
Posted by:"Craig" (firebirdwebg..@hotmail.com)
Date:Fri, 28 Dec 2007 16:53:34

And, a disconnect will ONLY be seen if its gracefull..

If you pull the cable out of the wall, Neither side will ever see it, unless
one side attempts to send data.


"Craig" <firebirdwebguy@hotmail.com> wrote in message
news:4775862c$1@newsgroups.borland.com...
> There is ONLY 1 way to know if the connection is real..
> Try to send data. Thats it.. A TCP/IP connection isnt really a connection
at
> all.
>
>
> "soonic" <xxsoonic@op.pl> wrote in message
> news:477574bc@newsgroups.borland.com...
> > >
> > > You can't.  Not accurately, anyway, because the OS itself can't do
that
> > > reliably.
> > >
> >
> > Well, then maybe you cen help me to solve the problem other way.
> >
> > I have this procedure where I catch the problem with connection. My
> > application is a server and client at the same time.
> >
> >
> > 'netunit.pas'
> > //var  procedure DisconnectServer;
> >
> > procedure TReadingThread.Execute;
> > begin
> >   try
> >     while not Terminated do
> >     begin
> >       FData.ReadFrom(FConn);
> >       if not Terminated then Synchronize(UpdateGrid);
> >     end;
> >   except
> >      // DisconnectServer;
> >     Synchronize(DisconnectServer);
> >   end;
> > end;
> >
> > //procedure DisconnectServer;
> > procedure TReadingThread.DisconnectServer;
> > begin
> >   with MainForm do
> >   begin
> >     //for server
> >     if IdTCPServer.Active = False then exit;
> >     IdTCPServer.Active:=False;
> >
> >     //for client
> >     if ReadingThread <> nil then ReadingThread.Terminate;
> >     if IdTCPClient.Connected then IdTCPClient.Disconnect;
> >   end;
> >   if ReadingThread <> nil then
> >   begin
> >     ReadingThread.WaitFor;
> >     FreeAndNil(ReadingThread);
> >   end;
> > end;
> >
> > I have also a button which I can use to disconnect manually.
> >
> > 1) I call DisconnectServer in both ways: just  DisconnectServer and
> > Synchronize(DisconnectServer);
> > I used always the first option until today. The problem I get, is that
my
> > application hangs when I put DisconnectServer in clause try...except and
> > press manually disconnect button. If I add this procedure to
> TreadingThread
> > class and use synchronize then its ok (when I disconnect manually)
because
> > there is condition    if IdTCPServer.Active = False then exit;
> >
> >
> > 2) Main problem. I use option with Synchronize(DisconnectServer). It
fires
> > automatically when I unplug the network cable but my program freezes. Of
> > course it passes the condition IdTCPServer.Active = False then exit and
> then
> > freezes. I know that it hangs because I'm calling from
> > TReadingThread.Execute but how to solve this so it won't freeze?
> >
> > s.

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive