I need help with a TCPServer and TcpClient problem. I am using Delphi XE2 and Indy 10.5.
I made server and client programs based on a popular screen capture program:
ScreenThief - stealing screen shots over the Network
My client program sends a .zip
file and some data to the server. This works normally a few times individually, but if I put it to a stress test where transmissions are performed 5 times in 5 seconds via a timer, exactly on attempt #63 the client can not longer connect to the server:
Socket Error # 10053
Software Caused Abort connection .
Apparently it seems that the server runs out of resources and cannot accept any more client connections.
After the error message, I can not connect to the server in any way - not in individual tests, not in stress tests. Even if I exit and restart the client, the error persists. I have to exit and restart the server, and then the client can connect again.
Sometimes socket error #10054 occurs in the client, and this makes the server totally crash and has to be restarted.
I do not know what is going on. I just know that if the server has to be restarted from time to time, it is not a robust server.
Here are the sources of the client and server so that you guys can test them:
http://www.mediafire.com/download/m5hjw59kmscln7v/ComunicaTest.zip
Run the server, run the Client, and check "Just check to Run Infinite". In the test, the server runs in localhost
.
Can anyone help me ? Remy Lebeau ?
I see problems with your client code.
You are assigning
TCPClient.OnConnected
andTCPClient.OnDisconnected
event handlers after callingTCPClient.Connect()
. You should be assigning them before callingConnect()
.you are assigning
TCPClient.IOHandler.DefStringEncoding
after sending all of your data. You should be setting it before sending any data.You are sending the
.zip
file size as bytes, but then sending the actual file content using aTStringStream
. You need to use aTFileStream
orTMemoryStream
instead. Also, you can get the file size from the stream, you don't have to query the file size before then creating the stream.You have a complete lack of error handling. If any exception is raised while
btnRunClick()
is running, you are leaking yourTIdTCPClient
object and not disconnecting it from the server.I see some problems with your server code as well:
your
OnCreate
event is activating the server before theClients
list has been created.various misuse of
TThread.LockList()
andTThreadList.Unlock()
.using
InputBufferIsEmpty()
andTRTLCriticalSection
unnecessarily.lack of error handling.
using
TIdAntiFreeze
, which has no effect on servers.Try this instead:
Client:
Server: