Click here to Skip to main content
15,884,083 members
Articles / Programming Languages / XML

Screen Cast Server

Rate me:
Please Sign up or sign in to vote.
4.85/5 (17 votes)
15 Sep 2009CPOL2 min read 42.8K   2.6K   44   6
A screen cast server with client

SCS

Introduction

Ever wanted to see what is on someone else's screen but you didn't want to install PC Anywhere or Configure VNC?

Well now, it's possible to just run the Screen Cast Server and view that person's screen from your Screen Cast Client.

Warning: This code is not optimized for Internet usage and does not imply that it is better than PC Anywhere, VNC, or any other 3rd party application on the market. It is also not encrypted in any way and is thus not secure.

Background

I am constantly bugged by end users that say "I did click the right button" or "I did select that first". I decided that I want to see what they see when they use my apps, so I developed this simple little Client - Server screen casting utility. The server part is so small you can copy paste it into any of your apps and call it when that app loads.

Using the Code

Using this code is simple if you know a little bit of Remoting.

The server part uses Remoting to open a port and exposes the CastScreen method:

C#
ScreenHost.ScreenObject remoteObject = new ScreenHost.ScreenObject();

//************************************* TCP *************************************//
// using TCP protocol

TcpChannel channel = new TcpChannel(8082);

ChannelServices.RegisterChannel(channel, false);

RemotingConfiguration.RegisterWellKnownServiceType(typeof(ScreenHost.ScreenObject), 
                      "CastScreen", WellKnownObjectMode.SingleCall);

//************************************* TCP *************************************//

The exposed method (CastScreen) resides in a shared class that is used by both the client and the server:

C#
public MemoryStream CastScreen(int formatType)
{
  //Get the Screen Bounds
  Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty));

  //Switching here to get formatType into imgFormat
  using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
  {
      using (Graphics g = Graphics.FromImage(bitmap))
      {
         g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
      }

      //Convert the Image to a the given format
      MemoryStream ms = new MemoryStream();
      bitmap.Save(ms, imgFormat);
      return ms;
  }
}

The client application has a timer that acts as the refresh rate and it makes a BackGroundWorker run the code to get the image from the server.

C#
//Setup the Host Instance

try
{
   hostInstance = 
     (ScreenHost.ScreenObject)Activator.GetObject(typeof(ScreenHost.ScreenObject), 
      "tcp://" + hostIP + ":8082/CastScreen", null);
   if (hostInstance != null)
   {
      ms = hostInstance.CastScreen(imgFormat);
      img = Image.FromStream(ms);
      updatePictureBox(picCast, img);
      updateText(lblMessage, "Screen Updated - " + DateTime.Now);
   }
}
catch (Exception exc)
{
   if (bgWorker1.IsBusy)
   { bgWorker1.CancelAsync(); }
     
   updateText(lblMessage, exc.Message);
}

Points of interest

The best thing about this is that there are so many applications for this and it can be embedded into any of your applications. If you want, you can give the user the option of clicking a button first to start the server or you can make it fire when the form loads.

History

This is version one of this app. If anyone wants to upgrade it, please go ahead. Just keep me in the loop and send me a copy.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Backbase
Netherlands Netherlands
Senior Solutions Architect.

I reject your code and substitute my own Smile | :) !

Comments and Discussions

 
BugThink it has a memory leek Pin
Andy Wyatt225-Aug-14 0:41
Andy Wyatt225-Aug-14 0:41 
AnswerRe: Think it has a memory leek Pin
Andy Wyatt225-Aug-14 1:46
Andy Wyatt225-Aug-14 1:46 
GeneralMy vote of 1 Pin
Dave Kreskowiak16-Sep-09 3:58
mveDave Kreskowiak16-Sep-09 3:58 
GeneralRe: My vote of 1 Pin
ozkan.pakdil17-Sep-09 0:53
ozkan.pakdil17-Sep-09 0:53 
GeneralRe: My vote of 1 Pin
cwp4223-Sep-09 22:48
cwp4223-Sep-09 22:48 
Dear Linoxxis,
thanks for your article.
And you Dave should respect that article, the working code, the interesting theme and maybe a greater interested audience.
So a 1 is absolutle not fair.

cwp42

GeneralSo Awesome Pin
Xmen Real 15-Sep-09 7:38
professional Xmen Real 15-Sep-09 7:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.