Problem with stream overflow

Discussion in 'C++' started by Ciccio, May 1, 2006.

  1. Ciccio

    Ciccio Guest

    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;
    }
    Ciccio, May 1, 2006
    #1
    1. Advertising

  2. Jonathan Mcdougall, May 1, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rasmusson, Lars
    Replies:
    1
    Views:
    723
    popov
    Apr 30, 2004
  2. Replies:
    9
    Views:
    617
    Alex Buell
    Apr 27, 2006
  3. Alexander Korsunsky

    get stream mode flags from an opened stream

    Alexander Korsunsky, Feb 17, 2007, in forum: C++
    Replies:
    1
    Views:
    444
    John Harrison
    Feb 17, 2007
  4. dolphin
    Replies:
    6
    Views:
    545
    Thomas Fritsch
    Mar 18, 2007
  5. mrstephengross
    Replies:
    3
    Views:
    392
    James Kanze
    May 10, 2007
Loading...

Share This Page