Hello Sela, - Are you taken into account that nRead also can be 0 or -1 ? - You create a TStream in every OnDataAvailable. I think you need the TStream to put the file in right ? Then only create it one time.
--- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz Thursday, November 17, 2005, 21:50, Selahattin Erkoc wrote: > hi, > I have used both compenets to send/receive text but now I'm trying to > use it for sending files.. > so I tried just simple to open the file binary, read it and send it to > the Server > TCommand = record > ID : Integer; > end; > TFileBuf = record > ID : Integer; > bufSize : Integer; > buf: array[0..1024] of Byte; > end; > //send the file (client) > while ... > BlockRead(f, FileBuf.buf, SizeOf(FileBuf.buf), FileBuf.bufSize); > FBuf.ID:=1; > WSocket1.Send(@FileBuf, sizeof(FileBuf)); > end; > before sending the file, the server gets some information about it > (size, name, ...) - this works fine but if I try to send a file the > server doesn't get any new record from the client: > //ondata aviable... > var > buf : array[Word] of Byte; > fData : TMemoryStream; > Filebuf : ^TFileBuf; > Command : TCommand; > FileInfo : TFileInfo; > OldPos : Integer; > begin > fData:=TMemoryStream.Create; > GetMem(Filebuf,SizeOf(TFileBuf)); > with sender as TWSocketClient do begin > nRead := Receive(@buf, High(Buf)- Low(buf)); > OldPos := fdata.Position; > fData.WriteBuffer(buf, nRead); > try > fData.Position := OldPos; > fdata.ReadBuffer(Command, SizeOf(Command)); > if Command.ID = 1 then begin > fData.Position := OldPos; > fdata.ReadBuffer(Filebuf, SizeOf(Filebuf)); > if CanWriteToFile then begin //write data to file > BlockWrite(f, Filebuf.buf, SizeOf(FileBuf.bufSize)); > currspeed:= currspeed + FileBuf.bufSize; > Numwritten:=Numwritten+FileBuf.bufSize; > end; > end else > //... code for getting Fileinfo (works) > some strange thing I recognized was that the client was sending/reading > data in full speed while I was debugging and executing my code step by > step :( > has anybody an idea to solve this problem or another way to send a file > except ftp or http (it shoud be recordbased)? > ps sorry for the huge code in my mail > thx Sela -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be