Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Jun : IdTCPClient.Socket.Recv - Hangs

www.cryer.info
Managed Newsgroup Archive

IdTCPClient.Socket.Recv - Hangs

Subject:IdTCPClient.Socket.Recv - Hangs
Posted by:"brandon" (someo..@microsoft.com)
Date:Wed, 21 Jun 2006 11:55:09

Greetings,

I am attempting to transfer a file with TidTCPClient and Server. I do not
want to disconnect the client to indicate the file transfer is complete, so
I have the following code wich works...Mostly.


var
  Buffer: array[1..10000] of Char;
  nReceived: Integer;
begin
  str := TFileStream.Create('c:\temp\rcvd.jpg',fmCreate);
  try
     while True do
        begin
           nReceived := IdTCPClient1.Socket.Recv(Buffer, SizeOf(Buffer));
           if nReceived <= 0 then Break
              else Str.Write(Buffer, nReceived);
           Sleep(200);
        end;
  finally
     FreeAndNil(str);
  end;
end;

The problem apears to be that when the last "chunk" of data is read, if it
is less than the SizeOfBuffer, the application hangs. While the application
is hung, the rcvd.jpg file size is 0. As soon as the application is reset,
the file is written with the correct size and can be viewed. The hanging is
on nReceived := IdTCPClient1.Socket.Recv line. Tracing into the code a
little farther, IdStackWindows.WSRecv is where the real hangup occurs.

Is there a timeout that needs to be set, or do I need to lay a trap for
EOF,...?

tia
Brandon

Replies:

www.cryer.info
Managed Newsgroup Archive