Click here to Skip to main content
Click here to Skip to main content

Screen Cast Server

, 15 Sep 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
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:

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:

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.

//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 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)

Share

About the Author

Pieter Alec Myburgh
Software Developer (Senior) Process Computing Technology
South Africa South Africa
Senior Software Engineer & Manager.
 
I reject your code and substitute my own!
Follow on   Twitter

Comments and Discussions

 
BugThink it has a memory leek PinmemberAndy Wyatt225-Aug-14 1:41 
AnswerRe: Think it has a memory leek PinmemberAndy Wyatt225-Aug-14 2:46 
GeneralMy vote of 1 PinmvpDave Kreskowiak16-Sep-09 4:58 
GeneralRe: My vote of 1 Pinmembermascix17-Sep-09 1:53 
GeneralRe: My vote of 1 Pinmembercwp4223-Sep-09 23:48 
GeneralSo Awesome PinmemberXmen W.K.15-Sep-09 8:38 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141220.1 | Last Updated 15 Sep 2009
Article Copyright 2009 by Pieter Alec Myburgh
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid