简体   繁体   English

树莓派 VNC 连接失败

[英]Raspberry Pi VNC fail connection

I face a problem that I can ping to correct IP address, it have no loss.我遇到一个问题,我可以 ping 以纠正 IP 地址,它没有丢失。 And also I use nmap ping the pi address, and I get it correctly.而且我还使用 nmap ping pi 地址,我得到了正确的结果。 Then I using VNC viewer to try access to pi, but it always show up "The connection was refused by the host computer"然后我使用VNC查看器尝试访问pi,但它总是显示“主机拒绝连接”

Did u all have any idea?大家有什么想法吗?

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.您的问题表明连接尝试已访问您的 Raspberry Pi,但相关端口上没有运行任何服务,因此连接被拒绝。 I think, this is because the VNC service is not running on your Raspberry Pi.我想,这是因为 VNC 服务没有在你的树莓派上运行。

Update 1更新 1
Raspbian now comes with the server by default thanks to a partnership with RealVNC, it just needs to be enabled.由于与 RealVNC 合作,Raspbian 现在默认带有服务器,只需要启用它。

Original原来的
You must enable VNC Server on your Raspberry Pi using terminal您必须使用终端在 Raspberry Pi 上启用 VNC 服务器

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.或者您也可以使用sudo raspi-config命令在命令行上启用 VNC 服务器。

Advanced Options->VNC:Yes

Now you can connect to the VNC Server using a application such as VNC Viewer.现在,您可以使用 VNC 查看器等应用程序连接到 VNC 服务器。

I have been having this issue with my Raspberry Pi Zero W even though it worked perfectly beforehand.我的 Raspberry Pi Zero W 一直有这个问题,尽管它事先工作得很好。 This page https://www.realvnc.com/en/connect/docs/raspberry-pi.html should help.这个页面https://www.realvnc.com/en/connect/docs/raspberry-pi.html应该会有所帮助。

I ran vncserver in a ssh window after verifying the interface settings in raspi-config.在验证 raspi-config 中的接口设置后,我在 ssh 窗口中运行了vncserver 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.它启动了 VNC 服务器,并给了我 VNC 服务器标语和带有端口号的 IP 地址,如下面链接的照片所示。

vncserver output vncserver 输出

After running that command I was able to get the VNC Viewer on my windows machine to connect to the pi.运行该命令后,我能够在我的 Windows 机器上获取 VNC 查看器以连接到 pi。

I then ran sudo systemctl enable vncserver-x11-serviced.service in the ssh window so that it would start automatically on subsequent reboots.然后我在 ssh 窗口中运行sudo systemctl enable vncserver-x11-serviced.service以便它在后续重新启动时自动启动。

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.将鼠标或键盘插入 Raspberry Pi 零,唤醒屏幕和 VNC 连接。
  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.等待大约 5 - 10 分钟,这是屏幕保护程序启动的时间,似乎唤醒了 VNC 连接。 but don't wait to long other wise run this command to get things going via ssh "systemctl start vncserver-x11-serviced.service" .但不要等待太久,否则明智地运行此命令以通过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.我对 Raspi B3+ 的看法不如 Zero H。

The last was plug in both monitor and mouse and that for sure fixes the VNC issues but defeats the headless connection.最后是同时插入显示器和鼠标,这肯定会解决 VNC 问题,但会破坏无头连接。 It seems that running headless and the screen/saver are somehow related but just not smart enough to figure it out.似乎无头运行和屏幕/保护程序有某种关联,但不够聪明,无法弄清楚。

pinging to any service will only tells us that whether the server is currently listening on that port or not. ping 任何服务只会告诉我们服务器当前是否正在侦听该端口。 It will not tell you the possible result to connection request asked by client.它不会告诉您客户端询问的连接请求可能的结果。

It seems that, you have installed VNC server but not started it properly.看来,您已经安装了 VNC 服务器,但没有正确启动它。 Use this command to start it...使用此命令启动它...

# vncserver start

Also recheck the port number is correct or not.还要重新检查端口号是否正确。

With the Rasp Pi 4 - had connecting fail after rebooting both the server and client (both Rasp Pi 4s).使用 Rasp Pi 4 - 在重新启动服务器和客户端(两个 Rasp Pi 4s)后连接失败。 Took a while to realize that I have two clients: One named "VNC Client", the other "VNC Viewer for Google Chrome".花了一段时间才意识到我有两个客户端:一个名为“VNC Client”,另一个名为“VNC Viewer for Google Chrome”。 The former works, the latter doesn't.前者有效,后者无效。

For people using newer version of Raspberry, VNC option is found under:对于使用较新版本 Raspberry 的人,可以在以下位置找到 VNC 选项:

Config>Interface Options配置>接口选项在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM