Newby
to Indy.
I am
having some problems with the Indy TidTCPClient component. Apart from trying to
get my head around having no events fire when data comes in.
I have
a routine that sends data to a TidTCPServer, which then sends results back to
the client. This seems to work fine.
I have
defined a thread as per the Indy example to handle input at the client.
//
routine to read data from the socket
procedure TSocketIO.HandleInput;
begin
frmMain.idClient.ReadBuffer(Res, SizeOf(Res));
begin
frmMain.idClient.ReadBuffer(Res, SizeOf(Res));
do stuff with the buffer...
end
;
// The
thread execute method
procedure TSocketIO.Execute;
begin
while not Terminated do
begin
if not frmMain.idClient.Connected then
Terminate
else
Synchronize(HandleInput) ;
end;
end;
begin
while not Terminated do
begin
if not frmMain.idClient.Connected then
Terminate
else
Synchronize(HandleInput) ;
end;
end;
//
Send the data in blocks
procedure TfrmMain.StartData(var Message: TMessage)
;
begin
begin
repeat
idClient.WriteBuffer(Command, SizeOf(Command));
idClient.WriteBuffer(Block, SizeOf(Block));
idClient.WriteBuffer(Block, SizeOf(Block));
until NoMoreBlocks;
end;
end;
//
Start the send routine with a message and start the IO handler
thread
procedure TfrmMain.IdClientConnected(Sender:
TObject);
begin
SendMessage(Handle, WM_StartData, 1, 0) ;
IOHandler := TSocketIO.Create(True);
IOHandler.FreeOnTerminate:=True;
IOHandler.Resume;
end ;
begin
SendMessage(Handle, WM_StartData, 1, 0) ;
IOHandler := TSocketIO.Create(True);
IOHandler.FreeOnTerminate:=True;
IOHandler.Resume;
end ;
The
Send routine sends all the data (broken into handleable blocks) and after each
block I expect a response.
But the thread never starts. I thought a thread once resumed
kept running until terminated. If I put a breakpoint on the threads execute
code, it does nothing until all the send stuff is finished.
For
small sets of data this is fine, but the whole app just hangs after a while. I
assume the socket buffer is full and can't handle any more until it is read.
Some sets of data can be 30Mb+
The
server is in a service. Using logmessage, I can see the data come in and the
response being sent in the correct order.
Any
ideas? It would be really nice to have an event fire saying hey there's data
here to be read.
Example code (not the Indy examples) would be nice.
Cheers,
Dave.