Simple C# Screen sharing application

Andy Hin picture Andy Hin · Jul 21, 2010 · Viewed 39.9k times · Source

I am looking to create a very basic screen sharing application in C#. No remote control necessary. I just want a user to be able to broadcast their screen to a webserver.

How should I implement this? (Any pointer in the right direction will be greatly appreciated).

It does NOT need to be high FPS. Would be sufficient to even update ever 5s or so. Do you think it would be sufficient to just upload a screenshot ever 5 seconds to my web server?

Answer

Brian R. Bondy picture Brian R. Bondy · Jul 21, 2010

I previously blogged about how remote screen sharing software works here, it is not specific to C# but it gives a good fundamental understanding on the topic. Also linked in that article is the remote frame buffer spec which you'll also probably want to read up on.

Basically you will want to take screenshots and you can transmit those screenshots and display them on the other side. You can keep the last screenshot and compare the screenshot in blocks to see which blocks of the screenshot you need to send. You would typically do some sort of compression before sending the data.

To have remote control you can track mouse movement and transmit it and set the pointer position on the other end. Also ditto about keystrokes.

As far as compression goes in C#, you can simply use JpegBitmapEncoder to create your screenshots with Jpeg compression with the quality that you want.

JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.QualityLevel = 40; 

To compare file blocks you are probably best to create a hash on the old block and the new one, and then check to see if they are the same. You can use any hashing algorithm you want for this.