Raspberry Pi VNC fail connection

33,516

Solution 1

Your problem indicates that your Raspberry Pi was reached by the connection attempt, but that no service was running on the relevant port and hence the connection was refused. I think, this is because the VNC service is not running on your Raspberry Pi.

Update 1
Raspbian now comes with the server by default thanks to a partnership with RealVNC, it just needs to be enabled.

Original
You must enable VNC Server on your Raspberry Pi using terminal

sudo apt-get update
sudo apt-get install realvnc-vnc-server

or you can also enable VNC Server on the command line using the sudo raspi-config command.

Advanced Options->VNC:Yes

Now you can connect to the VNC Server using a application such as VNC Viewer.

Solution 2

I have been having this issue with my Raspberry Pi Zero W even though it worked perfectly beforehand. This page https://www.realvnc.com/en/connect/docs/raspberry-pi.html should help.

I ran vncserver in a ssh window after verifying the interface settings in raspi-config. It started the VNC Server and gave me the VNC Server catchphrase and the IP address with Port Number as shown in the photo linked below.

vncserver output

After running that command I was able to get the VNC Viewer on my windows machine to connect to the pi.

I then ran sudo systemctl enable vncserver-x11-serviced.service in the ssh window so that it would start automatically on subsequent reboots.

Solution 3

I've had this same problem but found a different reason. I found three ways to get around this error message.

  1. Plug a mouse or keyboard into the Raspberry Pi zero, waking up the screen and the VNC connection.
  2. Wait about 5 - 10 minutes which is the amount of time for the screen saver to kick in which seems to wake up VNC connection. but don't wait to long other wise run this command to get things going via ssh "systemctl start vncserver-x11-serviced.service".

I am hoping the new update they just published will fix this problem. I don't see this as much with the Raspi B3+ as with the Zero H.

The last was plug in both monitor and mouse and that for sure fixes the VNC issues but defeats the headless connection. It seems that running headless and the screen/saver are somehow related but just not smart enough to figure it out.

Share:
33,516
Jackdon Chew
Author by

Jackdon Chew

Updated on July 09, 2022

Comments

  • Jackdon Chew
    Jackdon Chew almost 2 years

    I face a problem that I can ping to correct IP address, it have no loss. And also I use nmap ping the pi address, and I get it correctly. Then I using VNC viewer to try access to pi, but it always show up "The connection was refused by the host computer"

    Did u all have any idea ?