Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Jan : Re: Problems with TIdTCPClient disconnecting after receiving first data
| Subject: | Re: Problems with TIdTCPClient disconnecting after receiving first data |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Wed, 31 Jan 2007 11:07:37 |
"Kiwi" <glen@custommadesoftware.co.nz> wrote in message
news:45c0e558$1@newsgroups.borland.com...
> I have an interesting problem in that when my client program
connects
> to a server app then requests data from the server - I get the data
back
> but the connection has been lost.
Then either 1) the server is probably closing the connection, 2) you
likely have a faulty network connection, or 3) your other code that
you did not show is closing the socket elsewhere.
> On the client side I have a thread to handle all the reading - this
thread
> runs for the duration that tthe client is connected as the server
app can
> send messages back to all connected clients at any time.
> except
> Raise;
> _Owner.SocketError:= True;
> Synchronize(ProcessError);
> Exit;
> end;
You are re-raising the exception BEFORE doing your cleanup work. That
code will never be called. You need to re-raise the exception AFTER
instead:
except
_Owner.SocketError:= True;
Synchronize(ProcessError);
Raise;
end;
> B:= _Owner.Connected; //At this point the result is false. -
Note no
> exception is raised.
Connected() does not raise an exception.
> This is the code that the client uses to send the command to the
server app:
Where is that being called from exactly? If not the same thread that
is reading, then are you re-using the same stream across thread
boundaries?
> B:= IsConnected; // Returns true at this stage
What is 'IsConnected'? Is it a variable or a function? If a
function, is it calling the IOHandler's Connected() method? If so,
then again, which thread is calling this code? It is not safe to use
Connected() acrosss multiple threads. If they call Connected() at the
same time, the IOHandler's InputBuffer could get corrupted.
> Any ideas would be much appreciated as I have spent many hours
trying
> to figure at just what is wrong.
You have not shown enough code, or described any errors, to diagnose
your problem.
Gambit
none