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();
TcpChannel channel = new TcpChannel(8082);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ScreenHost.ScreenObject),
"CastScreen", WellKnownObjectMode.SingleCall);
The exposed method (CastScreen
) resides in a shared class that is used by both the client and the server:
public MemoryStream CastScreen(int formatType)
{
Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty));
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
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.
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.