Saturday 15 January 2011

c# - Efficient way to send images via WCF? -


I am writing, writing WCF, LINQ and some other technologies from scratch, such as custom remote control applications like VNC I Keeping three main goals in mind:

  1. Instead of full desktop access, the server will provide 'remote control' at the application level (i.e. seamless window).
  2. Customers can select any application that runs on the server and can receive a flow of images from each of them.
  3. A customer can connect to more than one server simultaneously

Right now I am using WCF which sends an array of bytes that will be sent The window represents:

 using  (var ms = new MemoryStream ()) {Window.GetBitmap (). Save (MS, Image format.jpg); Frame Snapshot = MS ToArray (); }  

GetBitmap implementation:

  var wRectangle = GetRectangle (); Var image = new bitmap (wRectangle.Width, wRectangle.Height); Var gfx = graphics.from image (image); Gfx.CopyFromScreen (wRectangle.Left, wRectangle.Top, 0, 0, wRectangle.Size, CopyPixelOperation.SourceCopy); Return image;  

This is then sent through the WCF (TCPBinding and it is always on the LAN) and sent to the client without any such limit as a blank window. Goes:

 using  (var ms = new memorystream (_currentFrame.Snapshot)) {BackgroundImage = Image.FromStream (ms); }  

I would like to make this process as efficient as possible in both CPU and memory usage with the bandwidth that comes in third place. I aim to connect 10+ applications per server to connect the customer to a 5+ server.

Is the best method of my current method (continuing to use these technologies) and I can do anything to improve

  • Thoughts that I (But I have no experience):

    • Instead of using the Open Source Graphics Library to capture and save images.
    • Saving as a PNG or other image type instead of JPG.
    • Send Delta Image Every Time Instead of A Full Image
    • Try and create a compressed video stream instead of 'Record' windows and snapshots (MPEG?).
    • You should be aware of this point:

      • Transportation: TCP / Binary message encoding will be the fastest way to transfer your image data
      • Image Capture: Invite you to access P / your screen data, because it stores faster and more memory Consumption can happen. Some examples:, and
      • You should reduce your image data before sending;
        • Choose your image wisely, because the original compression in some formats (as JPG)
        • should be an example
        • to send a different image only , You can crop it and just send it to non-empty areas
      • Try to inspect your WCF messages This will help you understand how to format messages And it will help you identify how to mess up messages Small things done.

      Just after is going through all these steps and satisfied with your final code, you can download. This applies, "A simple protocol for remote access to graphical user interface, as it works at the framebuffer level, it applies to all window systems and applications, which include X11, Windows and Macintosh. The protocol used in RFB VNC is Virtual Network Computing). "


No comments:

Post a Comment