Home > Back-end >  About the socket send flow problem
About the socket send flow problem

Time:10-13

Send a picture through the flow, use TserverSocket and TClientSocket, receiving end read event is not triggered, please everybody to give directions

Send:
Void __fastcall TForm1: : BitBtn1Click (TObject * Sender)
{
TMemoryStream * tmpStream=new TMemoryStream ();
Graphics: : TBitmap * Bitmap1=new Graphics: : TBitmap ();
Image2 - & gt; Canvas - & gt; Pen - & gt; Color=clBlack;
Image2 - & gt; Canvas - & gt; 20,20,40,40 FillRect (TRect ());
Bitmap1 - & gt; The Assign (Image2 - & gt; Picture - & gt; Bitmap);
Bitmap1 - & gt; SaveToStream (tmpStream);
TmpStream - & gt; The Position=0;
S=ClientSocket1 - & gt; The Socket - & gt; SendStream (tmpStream);//send image
//tmpStream - & gt; The Clear ();//run this sentence is wrong, I do not know why?
}
The delete Bitmap1;
//delete tmpStream;//run this sentence is wrong, I do not know why?
}

Reception:
Void __fastcall TForm1: : ServerSocket1ClientRead (TObject * Sender,
TCustomWinSocket * Socket)
{
Int LenRcv=Socket - & gt; ReceiveLength ();
Unsigned char Buf [65536].
ZeroMemory (Buf, 65536);
Graphics: : TBitmap * Bitmap1=new Graphics: : TBitmap ();
TMemoryStream * tmpStream=new TMemoryStream ();
The Socket - & gt; ReceiveBuf (Buf, LenRcv);//receive packets and read into the buffer within
TmpStream - & gt; Write (Buf, LenRcv);//add to the flow M

Bitmap1 - & gt; LoadFromStream (tmpStream);//to read data from the flow M to JPG image object J
Image1 - & gt; Picture - & gt; Bitmap - & gt; The Assign (Bitmap1);//assigned to image1

The delete Bitmap1;
}

CodePudding user response:

Your top up, a little bit urgent

CodePudding user response:

//tmpStream - & gt; The Clear ();//run this sentence is wrong, I do not know why?
By blocking the way to send, asynchronous methods are likely to flow in usage

CodePudding user response:

No, run has been waiting for this sentence

CodePudding user response:

Try the sleep wait for a period of time again the clear?

CodePudding user response:

if (! ServerSocket1 - & gt; The Socket - & gt; Connections [0] - & gt; SendStream (ImageStream))
  • Related