C # LAN desktop sharing software (2)

Source: Internet
Author: User

C # LAN desktop sharing software (I)

If you run this software to view traffic monitoring, you will find 1 ~ Upload and download at around 2 Mb/s, and sometimes the error "invalid parameter" is reported. If you save the screen locally, each image may be 4 Mbit/s (bmp), 120KB (jpg ), 10 images are transmitted in one second. Therefore, the network traffic usage is high. We will solve these problems one by one.

1. Compress client Images

Compression function (using System. Drawing. Imaging; required ;)

                                     = = = = = .getImageCoderInfo(==  EncoderParameters(=  EncoderParameter(ecd, ] =                                              ImageCodecInfo getImageCoderInfo(==  (ImageCodecInfo ici =

The client thread execution body is changed

  (= [] b =

After compression, the image size is only about 38 kb.

 

2. Server Error Handling

The error "invalid parameter" is caused

 

[] B = [*]; = Image. FromStream (ms); // ms data error cannot be converted to Image

Why is ms invalid? The reason is that the image size exceeds the size of byte array B, or the returned data is lost or empty content.

Solution: Since the byte array capacity is small, we will increase its capacity. For example, byte [] B = new byte [1024*10000]; increased by 10 times

Because we have already compressed images on the client, we don't have to worry about this.

Another point is to determine whether the data is an image after receiving the data, and discard it if not.

Implementation Code

  getImage(MemoryStream ms,= =  

The server thread execution body is changed

  ([] b =  [ * =  (getImage(ms, =

No one will ask why not.

Int len = 0;

Byte [] B = new byte [1024];

While (len = hostSocket. Receive (B)> 0)

{Ms. write (B, 0, B. lenth)} receives data cyclically to save memory allocation.

 

It should be noted that, if you still have a better solution, please share it with us. Of course, this program is not complete yet. The above is just a solution to the problem.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.