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;
}
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;
}