pjc123
Posts: 922
Joined: Thu Mar 29, 2012 3:37 pm
Contact: Website

vnc from one pi to another pi shows local, not remote screen

Thu Mar 28, 2013 4:04 pm

So, a long time ago I set up my Windows PC to connect to my pi using tightvnc through a SSH tunnel. Works great.

So today I tried to vnc from one pi to another pi using the exact same technique, but it displays the local screen, not the remote one. I don't know why this is happening.

So here is the basic setup whether going from Windows to the pi, or from one pi to another. First I start the tightvncserver on the remote pi in an init.d script at boot. Here is the pertinent line in that script:

su pi -c '/usr/bin/tightvncserver -localhost :1 -geometry 1920x1000 -depth 24'

Then on the local pi I set up a tunnel either using putty or from the command line. This works fine and I can verify the encryption with Wireshark. The command line command is:

ssh pi@<ip of remote host> -L 5901:localhost:5901

Then on the local pi I open up a viewer:

xtightvncviewer 127.0.0.1:1

From Windows to the pi this brings up the remote pi's screen as I would expect. But if I do this from one pi to the other it displays the local screen, not the remote screen.
My Raspberry Pi Project Page:

https://www.flaminghellmet.com/launch/

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5623
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: vnc from one pi to another pi shows local, not remote sc

Thu Mar 28, 2013 5:50 pm

pjc123 wrote: So, a long time ago I set up my Windows PC to connect to my pi using tightvnc through a SSH tunnel. Works great.

So today I tried to vnc from one pi to another pi using the exact same technique, but it displays the local screen, not the remote one. I don't know why this is happening.

So here is the basic setup whether going from Windows to the pi, or from one pi to another. First I start the tightvncserver on the remote pi in an init.d script at boot. Here is the pertinent line in that script:

su pi -c '/usr/bin/tightvncserver -localhost :1 -geometry 1920x1000 -depth 24'

Then on the local pi I set up a tunnel either using putty or from the command line. This works fine and I can verify the encryption with Wireshark. The command line command is:

ssh pi@<ip of remote host> -L 5901:localhost:5901

Then on the local pi I open up a viewer:

xtightvncviewer 127.0.0.1:1

From Windows to the pi this brings up the remote pi's screen as I would expect. But if I do this from one pi to the other it displays the local screen, not the remote screen.
Hi pjc,
Things work fine for me when I do it this way:

Using PuTTY to ssh in with port forwarding of port 5901, on the netbook log on to Pi #1 and start the vnc server:

Code: Select all

pi@raspiblack ~ $ /usr/bin/tightvncserver -localhost :1

New 'X' desktop is raspiblack:1

Starting applications specified in /home/pi/.vnc/xstartup
Log file is /home/pi/.vnc/raspiblack:1.log
NB: I don't usually "auto-start" the server at boot time.

On the netbook:

Code: Select all

trevor@BlueElf:~$ /usr/bin/xtightvncviewer 127.0.0.1:1
Connected to RFB server, using protocol version 3.8
Enabling TightVNC protocol extensions
Performing standard VNC authentication
Password: 
Authentication successful
Desktop name "pi's X desktop (raspiblack:1)"
VNC server default format:
  32 bits per pixel.
  Least significant byte first in each pixel.
  True colour: max red 255 green 255 blue 255, shift red 16 green 8 blue 0
Using default colormap which is TrueColor.  Pixel format:
  32 bits per pixel.
  Least significant byte first in each pixel.
  True colour: max red 255 green 255 blue 255, shift red 16 green 8 blue 0
Using shared memory PutImage
Same machine: preferring raw encoding
ShmCleanup called
and all's as expected.

Now, before trying via another Pi, kill off the running server thus:

Code: Select all

pi@raspiblack ~ $ /usr/bin/tightvncserver -kill :1
Killing Xtightvnc process ID 2108
Now (after switching from VGA to HDMI mode on the monitor - I've only one :) ) boot up Pi #2, startx and then log in to Pi #1 via PuTTY etc. as before. Re-start the vnc server on Pi #1:

Code: Select all

pi@raspiblack ~ $ /usr/bin/tightvncserver -localhost :1

New 'X' desktop is raspiblack:1

Starting applications specified in /home/pi/.vnc/xstartup
Log file is /home/pi/.vnc/raspiblack:1.log
Now, in a terminal window on Pi #2, start the viewer:

Code: Select all

pi@raspiblue ~ $ /usr/bin/xtightvncviewer 127.0.0.1:1
Connected to RFB server, using protocol version 3.8
Enabling TightVNC protocol extensions
Performing standard VNC authentication
Password:
Authentication successful
Desktop name "pi's X desktop (raspiblack:1)"
VNC server default format:
  32 bits per pixel.
  Least significant byte first in each pixel.
  True colour: max red 255 green 255 blue 255, shift red 16 green 8 blue 0
Warning: Cannot convert string "-*-helvetica-bold-r-*-*-16-*-*-*-*-*-*-*" to type FontStruct
Using default colormap which is TrueColor.  Pixel format:
  16 bits per pixel.
  Least significant byte first in each pixel.
  True colour: max red 31 green 63 blue 31, shift red 11 green 5 blue 0
Same machine: preferring raw encoding
Again everything worked O.K.

The main things I do differently is NOT starting the server on boot-up and killing the original server before changing m/c's. The latter is not essential since one could just start a new server using "screen" :2 and port 5902 instead.
HTH, Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

pjc123
Posts: 922
Joined: Thu Mar 29, 2012 3:37 pm
Contact: Website

Re: vnc from one pi to another pi shows local, not remote sc

Thu Mar 28, 2013 6:26 pm

But basically you are doing the same exact thing. I have also tried it pi to pi without having tried from Windows first and it still didn't work. I will have to try it manually as you have done and see what happens; very weird problem.
My Raspberry Pi Project Page:

https://www.flaminghellmet.com/launch/

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5623
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: vnc from one pi to another pi shows local, not remote sc

Thu Mar 28, 2013 6:34 pm

pjc123 wrote: But basically you are doing the same exact thing. I have also tried it pi to pi without having tried from Windows first and it still didn't work. I will have to try it manually as you have done and see what happens; very weird problem.
Since I posted, I've spotted one other difference - I'm not requesting a specific "screen size" and the default is always less than my monitor's full size (whether on the netbook in VGA mode or on Pi#2 in HDMI/DVI mode). Hmmm...
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

pjc123
Posts: 922
Joined: Thu Mar 29, 2012 3:37 pm
Contact: Website

Re: vnc from one pi to another pi shows local, not remote sc

Thu Mar 28, 2013 6:41 pm

FTrevorGowen wrote:
pjc123 wrote: But basically you are doing the same exact thing. I have also tried it pi to pi without having tried from Windows first and it still didn't work. I will have to try it manually as you have done and see what happens; very weird problem.
Since I posted, I've spotted one other difference - I'm not requesting a specific "screen size" and the default is always less than my monitor's full size (whether on the netbook in VGA mode or on Pi#2 in HDMI/DVI mode). Hmmm...
Trev.
The screen comes up just fine in both cases, it is just that when I do pi to pi it is the local pi's computer screen that comes up, not the remote pi's screen, which is useless. When I do it from Windows to the pi it works properly.
My Raspberry Pi Project Page:

https://www.flaminghellmet.com/launch/

User avatar
jojopi
Posts: 3271
Joined: Tue Oct 11, 2011 8:38 pm

Re: vnc from one pi to another pi shows local, not remote sc

Thu Mar 28, 2013 6:42 pm

pjc123 wrote:ssh pi@<ip of remote host> -L 5901:localhost:5901
If you already have a vncserver :1 running locally then port 5901 is in use, and ssh should say:

Code: Select all

bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 5901
Could not request local forwarding.
You can use a different display number on each pi, or mangle the display number as it goes through the tunnel with -L 5902:localhost:5901.

It is not necessary to tunnel the port yourself anyway, because vncviewer can do this itself. This method automatically allocates a port that will not conflict with any local server too:

Code: Select all

xtightvncviewer -via $REMOTE_IP :1

pjc123
Posts: 922
Joined: Thu Mar 29, 2012 3:37 pm
Contact: Website

Re: vnc from one pi to another pi shows local, not remote sc

Thu Mar 28, 2013 6:55 pm

jojopi wrote:
pjc123 wrote:ssh pi@<ip of remote host> -L 5901:localhost:5901
If you already have a vncserver :1 running locally then port 5901 is in use, and ssh should say:

Code: Select all

bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 5901
Could not request local forwarding.
You can use a different display number on each pi, or mangle the display number as it goes through the tunnel with -L 5902:localhost:5901.

It is not necessary to tunnel the port yourself anyway, because vncviewer can do this itself. This method automatically allocates a port that will not conflict with any local server too:

Code: Select all

xtightvncviewer -via $REMOTE_IP :1
Hmmm, I start the tightvncserver on both pi's at bootup so they are ready to go, on whatever pi I decide is headless. So related to what you are saying, that looks like the problem. That indeed would be the difference between the way I do it with Windows, because I only have a client running on Windows. I will try everything manually as I stated before, when I get a chance, and see how it goes.
Last edited by pjc123 on Thu Mar 28, 2013 9:00 pm, edited 1 time in total.
My Raspberry Pi Project Page:

https://www.flaminghellmet.com/launch/

pjc123
Posts: 922
Joined: Thu Mar 29, 2012 3:37 pm
Contact: Website

Re: vnc from one pi to another pi shows local, not remote sc

Thu Mar 28, 2013 8:54 pm

SOLVED.

"xtightvncviewer -via $REMOTE_IP :1" solved the problem by picking a different port, with the added bonus of setting up the SSH tunnel. I just left the tightvncserver init scripts intact on both pis.

Thanks FTrevorGowen and jojopi....I think I have some hair left that I didn't pull out.
My Raspberry Pi Project Page:

https://www.flaminghellmet.com/launch/

Return to “Troubleshooting”