I use dephi7's client/server socket components to send a file with tfilestream from client to server.
I'am able to get the progress of file received at server side, but at client side, how d开发者_运维百科o i get the progress of the file sent ?
this is how I send the file:
fstream:=tfilestream.Create(opendialog1.FileName,fmOpenRead);
clientsocket1.Socket.SendStream(fstream);
Thanks and appreciate for any help.
It doesn't look like TClientSocket
provides any feedback of its progress. I see two alternatives:
Instead of
SendStream
, useTStream.Read
andTClientSocket.Socket.SendBuf
in a loop. Read a block of data from the stream and then send it. Repeat until you reach the end of the stream.Write a
TStream
descendant class that wraps (or decorates) another stream. ItsRead
,Write
, andSeek
methods can simply forward to the wrapped stream, but you can also add some events to the wrapper so you can be notified each time the socket code reads a block of data out of the stream — theSendStream
method essentially does the same thing that I described above in the first alternative.
精彩评论