Reputation: 3367
I'm building a client/server solution which needs to have screen sharing functionality. I have something already "working" but the problem is that it only works over internal network, because my methodology is not fast enough.
What I am basically doing is that the client makes a request for the server asking for a screen image each 5 seconds (for example). And this is the code which is processed once this requests are received:
private void GetImage(object networkstream)
{
NetworkStream network = (NetworkStream)networkstream;
Bitmap bitmap = new Bitmap(
SystemInformation.PrimaryMonitorSize.Width,
SystemInformation.PrimaryMonitorSize.Height);
Graphics g = Graphics.FromImage(bitmap);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), bitmap.Size);
g.Flush();
g.Dispose();
MemoryStream ms = new MemoryStream();
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
bitmap.Dispose();
byte[] array = ms.ToArray();
network.Write(array, 0, array.Length);
network.Flush();
ms.Dispose();
}
What are best methods to do what I'm trying to? I need to get at least 0.2 FPS (refresh each 5 seconds) Obs.: I'm using Windows Forms and it is being done over sockets.
How do TeamViwer and .rdp files work?
Upvotes: 1
Views: 3208
Reputation: 2491
What about using an existing implementation? Or learning from it? http://cdot.senecac.on.ca/projects/vncsharp/
Upvotes: 2
Reputation: 11040
You need to optimize your protocol, here are some suggestions:
Upvotes: 2
Reputation: 614
You can send only difference betwen present and last image. Look here: Calculate image differences in C#
If it wont be fast enough, you can divide your screen into smallers, like 100x100 or 50x50 bitmaps, check if this area had changed and if yes just send it to client.
Upvotes: 2