Problem with stream overflow

C

Ciccio

I send file with ClientSocket and I receive with ServerSocket.
If I setting (ByteReceive == 5000) for prove and I overflow the stream.
How I send I file? Thanks.


SEND:
TMemoryStream *StreamName = new TMemoryStream;
StreamName->LoadFromFile("c:\\1.pdf");
StreamName->Seek(0,0);
if (StreamName) ClientSocket1->Socket->SendStream(StreamName);

RECEIVE:
void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
TMemoryStream *Stream = new TMemoryStream;
int BufferSize = 1024;
BYTE *Buffer = new BYTE[BufferSize];
int ByteReceive;
static int val;

Stream->Seek(val,soFromBeginning);
ByteReceive = Socket->ReceiveBuf(Buffer,BufferSize);
Stream->Write(Buffer,BufferSize);
val += ByteReceive;
Memo1->Text = Stream->Size;

if (ByteReceive == 5000 ) {
Stream->Seek(0,soFromBeginning);
Stream->SaveToFile("c:\\2.pdf");
Stream->Clear();
delete Stream;
delete []Buffer;
val = 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top