Home > other >  TCP images, the computer client cannot bring receive bytes flow into the picture
TCP images, the computer client cannot bring receive bytes flow into the picture

Time:10-06

Recently doing wireless video transmission module, the machine use is stm32F103, camera use is ov2640, USES a TCP transport, under a machine as a server to sent pictures to the computer PC, now the machine can be normal to send data, the size of the first sending pictures, then send the data of the picture, but at the time of writing a machine, always there is no way to image from byte transfer back to images, trouble you help to look at, or any good screening method.
I receive function code:
_client=new TcpClient (ipadd, port);
Ns=_client. GetStream ();

Private void recvdata ()//receiving data
{

While (true)
{
int len=0;
Byte [] bitLen=new byte [8].
Len=ns. Read (bitLen, 0, bitLen. Length);
Long contentLen=BitConverter. ToInt64 (bitLen, 0).

Int size=0;
MemoryStream ms=new MemoryStream ();
While (size & lt; ContentLen)
{
//points to receive many times, each receiving 256 bytes,
Byte [] bits=new byte [256].
Int r=Ms. Read (bits, 0, bits. Length);

If (r & lt;=0) break;
Ms. Write (bits, 0, r);
The size +=r;
}
Image img=Image. FromStream (ms). is an error in this sentence, prompt parameter error
PictureBox1. Image=img;

For the Enabled=true;
Button2. Enabled=false;
Send. Enabled=false;

}
}

CodePudding user response:

Parameter error, suggest you don't check the parameters of the type and number

CodePudding user response:

There is a problem how do I know can't sending data into images.

CodePudding user response:

refer to the second floor weixin_38119310 response:
there is a question how do I know can't sending data into images

With the
Try
{... }
Catch
{... }
  • Related