Screen sharing between Raspberry PI and Mac OSx

fguillen picture fguillen · Sep 2, 2015 · Viewed 25k times · Source

I want to use the Screen Sharing OSx built-in App to manipulate the actual X session open in my Raspberry PI.

Just to be clear I want to see in my VNC session the same image the Raspberry is sending through the HDMI. So I can move the mouse in my computer and the cursor is also moving in the Raspberry screen.

I have tried several combinations of vnc-servers and configs but neither have worked.

Answer

fguillen picture fguillen · Sep 2, 2015

As I have spent several hours solving this I so answer my self in case someone needs the instructions as I would wanted to find them.

First, the most popular vnc-server (tightvncserver) is not fullfilling my specification that the X-session has to be the same in my VNC client App and in the Raspberry screen.

The vnc-server that does the work is x11vnc

Install x11vnc

sudo apt-get install x11vnc

Looks like it requires you to set up a password:

x11vnc -storepasswd

Test installation and connection

You can already start the vnc-server:

x11vnc -forever -usepw -display :0 -ultrafilexfer

Check the service is active and listening

$ sudo netstat -nlp | grep vnc
tcp        0      0 0.0.0.0:5900            0.0.0.0:*               LISTEN      2575/x11vnc  

And connect from your Mac just opening Screen Sharing and introducing the Raspberry's ip:

enter image description here

Make x11vnc to start on boot

Config:

# ~/.config/autostart/x11vnc.desktop
[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=X11VNC
Comment=
Exec=x11vnc -forever -usepw -display :0 -ultrafilexfer
StartupNotify=false
Terminal=false
Hidden=false

Be sure there is not problems to access to this file:

sudo chmod a+r ~/.config/autostart/x11vnc.desktop

Make the Raspberry to be visible in the sharing network of the Mac

sudo apt-get install netatalk
sudo apt-get install avahi-daemon
sudo update-rc.d avahi-daemon defaults

Config:

# /etc/avahi/services/afpd.service
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
   <name replace-wildcards="yes">%h</name>
   <service>
      <type>_afpovertcp._tcp</type>
      <port>548</port>
   </service>
</service-group>

Config 2:

# /etc/avahi/services/rfb.service
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">%h</name>
  <service>
    <type>_rfb._tcp</type>
    <port>5900</port>
  </service>
</service-group>

Restart service:

sudo /etc/init.d/avahi-daemon restart

Finding the Raspberry from your Mac

Using Finder into the section Shared > All... should be your Raspberry. From there you can click in the button Share Screen...

enter image description here