These are chat archives for IndySockets/Indy

9th
Aug 2016
fan_tangshan
@sainimu78
Aug 09 2016 03:15
I start a thread.
fan_tangshan
@sainimu78
Aug 09 2016 03:21
A connection thread in client
In thread.Execute
while(Terminated = False)do
if(client.Connected = False)then
client.Disconnect;
Sleep(100);
The client will get Run Error 204 while server transferring data in client transferring way.
The transferring way is
blob
blob
It is just like you told me before @rlebeau
fan_tangshan
@sainimu78
Aug 09 2016 03:29
Oh, sorry, my fault, I never thought it is a misusing of converting PByte to TIdBytes because I specified the size to IoHandler.Write.
fan_tangshan
@sainimu78
Aug 09 2016 04:57
Or the other way of asking that how to detect disconnection on TIdTCPClient ?
fan_tangshan
@sainimu78
Aug 09 2016 05:15
Here is my server.OnExecute doing
blob
Toggles between ReadBytes(8) and ReadBytes(argConn.bufSize)
blob
fan_tangshan
@sainimu78
Aug 09 2016 07:31
TIdTCPClient.Connected is not thread safe, I think.
A mutex needs to be added on TIdTCPClient.IoHandler.ReadBytes call in the receive thread and on TIdTCPClient.Connected in the connection thread.
I found that the client receive thread can be aborted by the exception of the calling IoHandler.ReadBytes, then the problem solved.
Remy Lebeau
@rlebeau
Aug 09 2016 16:27
You really shouldn't be calling Connected at all. Let the IOHandler throw an exception during read/write operations if the socket has been disconnected.
If you don't want the thread to terminate, catch the exception