Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 948187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:12:10+00:00 2026-05-15T23:12:10+00:00

i am trying to send a picture from ‘C:\picture.bmp’ to ‘c:\temp\picture.bmp’ using server and

  • 0

i am trying to send a picture from ‘C:\picture.bmp’ to ‘c:\temp\picture.bmp’ using server and client socket
clients onconnect event handler is as follow:

procedure TForm2.ClientSocket1Connect(Sender: TObject;
  Socket: TCustomWinSocket);
 var
  fs : tfilestream;
  begin
     fs := TFileStream.create('C:\picture.bmp', fmOpenRead);//picture allready exists
     socket.SendStream(fs);
     fs.free;             
end;

and servers onclientread as :

procedure TForm2.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
  fmm : tfilestream;
  iLen: Integer;
    Bfr: Pointer;
  begin

     iLen := Socket.ReceiveLength;
  GetMem(Bfr, iLen);
  fmm := TFileStream.Create('c:\temp\picture.bmp', fmCreate or 

fmShareDenyWrite);
  try
    Socket.ReceiveBuf(Bfr^, iLen);
    fmm.Write(Bfr^, iLen);
  finally
    FreeMem(Bfr);
    fmm.Free;
  end;

end;

picture is recieved/created but is either corrupt on was never recieved i.e created because of tfilestream.create method?
please help!what am i doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:12:10+00:00Added an answer on May 15, 2026 at 11:12 pm

    Despite its name, SendStream() is NOT guaranteed to send the entire stream (especially if you are using a non-blocking socket). Its return value returns how many bytes are actually sent. If less than the full size of the stream are sent in one call, you have to call SendStream() again, potentially many times, to finish sending the entire stream (the same problems exists with SendText() as well).

    On the other side, ReceiveLength() only reports how many bytes are available on the socket AT THAT MOMENT. That is likely to be less than the full stream being sent (likewise, ReceiveText() may not receive a full sent string either because it uses ReceiveLength() internally).

    The best way to send a stream (or any arbitrary data in general) is to send the data’s size first, then send the actual data afterwards. Keep calling SendBuf/Stream/Text() until that size is reached (if -1 is returned by a non-blocking socket without raising an exception, you have to wait for the socket’s OnWrite event to trigger before the socket can accept more data again). On the receiving end, read the size first, then keep reading until the specified size is reached. You may have to read in multiple triggering of the OnRead event before you get all of the data.

    Go to http://www.deja.com and http://forums.embarcadero.com to search the Borland/CodeGear/Embarcadero newsgroup/forum archives. I have posted example code many times before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to send a picture from a android device to a server and
I am trying to send emails from smtps (secure smtp) using Indy and the
Im trying to send multiple data items over a tcp socket from an android
am trying send an array to php file using $_POST ,still always getting an
I am trying to send data as a model from an html form to
I'm trying to upload a picture to a specific website using php cURL but
I'm trying to send an image file through a TCP socket in C, but
I'm trying to load images from a different website on my game, using www.LoadImageIntoTexture(...),
I have an Android application where I'm trying to send a picture to a
I am trying send the emails using the lotus notes using TNMSMTP component. What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.