If you have simple requirements then consider having a look at TClientSocket, TServerSocket on Internet tab. They can be used in Non Blocking or Blocking (Requires thread) modes. They are heaps easier to use than Indy and work well.
At 12:23 21/11/2002 +1300, you wrote:
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));
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;
// Send the data in blocks
procedure TfrmMain.StartData(var Message: TMessage) ;
begin
repeat
idClient.WriteBuffer(Command, SizeOf(Command));
idClient.WriteBuffer(Block, SizeOf(Block));
until NoMoreBlocks;
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 ;
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.
----------------------------------------------------------------------
Donovan J. Edye [www.edye.wattle.id.au]
Namadgi Systems [www.namsys.com.au]
Voice: +61 2 6285-3460
Fax: +61 2 6285-3459
TVisualBasic = Class(None);
Heard just before the 'Big Bang': "...Uh Oh...."
----------------------------------------------------------------------
GXExplorer [http://www.gxexplorer.org] Freeware Windows Explorer
replacement. Also includes freeware delphi windows explorer components.
----------------------------------------------------------------------