How does a Mac’s Screen Sharing service work

remote desktopscreen-sharing

What components does it have and how do they work? What protocols are supported? What I only know of is it is compatible with VNC (as a client and as a host).

I'm interested in knowing more technical details and play around with them.

Best Answer

If we are speaking only about Screen Sharing (SS) (forgetting ARD), it is working as follows:

First, there is a daemon configuration file (/System/Library/LaunchDaemons/com.apple.screensharing.plist). It contains a record that tells launchd to start SS Server (and then SS Agent) every time when someone connects to port 5900. The server is located at /System/Library/CoreServices/RemoteManagement/screensharingd.bundle, the agent is at /System/Library/CoreServices/RemoteManagement/ScreensharingAgent.bundle.

The SS Server is the main part of SS Service. It performs network interacting, implements used protocols, performs image encoding, authentication and so on. In turn, SS Agent impersonates current user and handles things like providing image of user screen, “pressing” keys, “moving” mouse.

(AFAIR, this separation began with Mac OS X 10.7. Formerly the service was monolithic, was named AppleVNCServer and has been always running while the “Screen Sharing” switch in System Preferences was on).

SS Service also can start the following helpers as needed:

  • SSPasteboardHelper (located in SS Agent bundle) — pastes pasteboard data to system pasteboard as it arrives from the client,
  • SSAssistanceCursor — appeared just recently, I’m wondering what it is for,
  • SSFileCopyReceiver / SSFileCopySender (in SS Server bundle) — is used for transmitting/receiving files.

As for protocols, SS Service uses the same RFB protocol as all VNC clients, but with some specific extensions. The server reports that it supports protocol version 3.889 (most other servers report versions 3.3 to 3.8). It also supports most common codecs — raw, ZLib, ZRLE — as well as Apple’s custom ones (black-and-white and grayscale ZLib, and “adaptive” codec that uses JPEG-like compression algorithm). Also there are many Apple-specific protocol extensions, implementing drag-and-drop, files transmission, automatic pasteboard synchronization, transmission of gesture events, and so on.

This is a very general explanation, but if you ask a more specific question, I’ll be glad to help.