# VNC servers

Any machine that runs a VNC server can be on the wall: a virtual machine whose hypervisor shows
its screen that way (QEMU, libvirt and Unraid, by the port they give each guest: see
[Proxmox and virtual machines](https://qkvm.com/docs/proxmox-and-virtual-machines); a guest of Proxmox has a kind of its
own), a desktop with TigerVNC, TightVNC, RealVNC or x11vnc on it, a management controller whose own
VNC server is switched on. Choose *VNC servers* in *Add KVMs*, type the address with its port after a
colon where it is not 5900 (`192.168.1.20:5901`), and the VNC password; or type
`vnc://192.168.1.20:5901` with *KVMs and servers* chosen, which says the same. The tile is named
after the name the server gives itself. *Find KVMs on my network* lists what greets as a VNC
server on ports 5900 and 5901.

What works, and how:

- **The picture.** qKVM speaks RFB (RFC 6143), the protocol of VNC, in Python: versions 3.3, 3.7
  and 3.8; the Raw, CopyRect, Hextile, ZRLE and Tight encodings, JPEG within Tight included
  (OpenBMC's console sends that); a screen that changes its size. It asks for one pixel format of
  its own choosing and never leaves that to the server. It stays connected for as long as the
  machine is on the wall, as a viewer that shares the server with whoever else is connected, and
  asks for what changed every quarter of a second while somebody looks at the wall, every ten
  seconds while nobody does. A server that pushes frames at its own pace (obmc-ikvm does) is read
  all the same, and what it pushes while nobody looks is let go of without being decoded. The
  screen is kept as three bytes a pixel: a 1920 by 1080 screen takes 6 MB, and a screen wider or
  taller than 8192 pixels, or of more than 16 million pixels in all, is not shown.
- **Keys and text** from the action menu go as X11 keysyms, which is what the protocol has: the
  server's own keyboard layout turns them into keys. A key combination is pressed in order and let
  go of in the other. Typed text is sent character by character, each as the keysym of that
  character (Latin-1 characters as themselves, others as Unicode keysyms); what the machine makes
  of a character its layout has not got is the server's business. Ctrl+Alt+Del is a chord like any
  other.
- **Live, with keyboard and mouse.** Enlarged, its screen comes over the [live line](https://qkvm.com/docs/live-view-and-control)
  on the tile's own connection (one connection to the server, whatever the number of viewers),
  asked for what changed 25 times a second while somebody watches, and what a server's pictures
  cost to draw is shared out as below. *Control* takes its keyboard and mouse, one person at a
  time, as for every machine: a key goes as RFB's key event with the keysym of that key (Shift
  and the rest go as keys of their own, and the server's layout decides what they make), the
  pointer as a place in the screen's pixels with the buttons held, a notch of the wheel as a press
  and a release of its button; the back and forward buttons have none in RFB. Whatever was down
  is let go of whenever the line loses them (given back, taken over by an admin, the line closed
  or dropped, fifteen minutes without input, the wall stopping). A server whose password stands
  rejected has no live line; its tile says why. A server set to view only (a view-only password,
  x11vnc's `-viewonly`) takes the events and does nothing with them, which qKVM cannot see: the
  picture shows it. Over plain `vnc://` the keys go in the clear, as the password's answer does
  (below).
- **The password** goes the way VNC authentication has it: the server's challenge encrypted with
  DES under a key made of the password's first eight characters (the rest is not looked at, by any
  server). That is weak, as RFC 6143 itself says: anybody who can read the line can take the
  challenge and the answer away and try passwords against them at leisure, and the pictures and
  keys that follow are in the clear. Keep VNC servers on a network you trust or behind a tunnel,
  and give the wall a VNC password that is used for nothing else. Over plain `vnc://` the answer
  to the challenge goes to whatever answers at that address, since the protocol gives the wall no
  way to tell the server from an impostor. Where a server speaks TLS from the first byte (some
  management controllers do), type `vncs://`: the certificate is remembered on first contact, as
  for every device, and nothing is sent to what shows another. VeNCrypt, which puts TLS inside the protocol, is not spoken;
  a server that offers only that, or another way of signing in that qKVM does not speak, is
  said to on its tile. A server that asks for no password (security type None) is added with the
  password left empty.
- **A rejected password is left alone**, on the same ladder as a KVM's (a minute, five, fifteen,
  then an hour), and while it waits the server is still asked whether it is there, by its greeting
  alone (inside TLS at a `vncs://` address). VNC servers shut an address out after a few wrong
  passwords, for you as well.
- **A VNC server has no number of its own**: it is known by its address and by the name it gives
  itself, and a machine added under two addresses is two tiles.
- **What a VNC server cannot do from here:** there is no power button, no reboot, no Wake-on-LAN
  list, no keep-awake; the action menu offers them until it knows better, and each answers that a
  VNC server cannot do that. There is no *Open console* either, since a VNC server has no page of
  its own; a console link typed into the tile (the hypervisor's page, say) is used as it is.
- **What a server sends is not believed.** Every length is checked against the screen the server
  announced before room is taken for it; a rectangle outside the screen, a stream that inflates
  past what its rectangle can hold, a message of a kind qKVM does not read, floods and stalls end
  the connection with a named reason on the tile, and the server is left alone for a while: one
  that sent what qKVM does not take for fifteen seconds, then twice as long each time it does so
  again, four minutes at the most, until a connection to it goes well. One that lets qKVM in and
  hangs up, at once or after a frame, is connected to as one that is down is: a second later, then
  twice as long each time, a quarter of a minute at the most. A connection that drew a frame and
  is found there five seconds after it began (on a still screen, at its next answer, within a
  minute) is the server there again. One that ends every connection after a time of its own
  (TigerVNC's MaxConnectionTime, a proxy's limit) is connected to again at once the first time;
  each end after that, before a connection has served four minutes, waits longer (15 seconds, a
  minute, then five), and its tile says that it ends every connection, not that it is offline,
  also while nobody looks. Somebody who watches it enlarged, and keys sent to it, have it
  connected at once all the same. (A server that stops answering is one that is down, as
  above.) What a server's pictures cost to draw is shared out,
  since a few kilobytes can cost seconds of drawing: every server's pictures are drawn in the
  same two threads, a few milliseconds at a time, and reading what the servers send is counted
  with it, one server's in half of the program's time at the most and every server's together in
  three quarters (each may take a second's worth at once). JPEGs are decoded in their server's own
  worker and drawn in a thread of that server's own, as many at a time as a tenth of a second
  takes, and its share counts what the worker worked. A server whose
  pictures cost much to draw is shown more slowly, and the others, and the rest of qKVM, go on:
  their pictures wait a few milliseconds at a time behind its own, some tens where a stream of a
  large screen is inflated in one go. One whose pictures take a second or more to decode or draw,
  more than three times in a minute, is treated as one that sent what qKVM does not take (above).
  What every server's updates hold at once, beyond their screens, is held to 512 MB, and any one
  server's to a quarter of it (a rectangle that needs more alone, and one server at a time): an
  update that does not fit waits for others to be drawn, and one that fits does not wait behind it
  unless it has waited ten seconds.

VNC support was typed from RFC 6143 and from TightVNC's description of its encoding, and tried
against a stand-in server written for the purpose, which speaks every version, both ways of
signing in and every encoding above, and misbehaves in the ways tested. A test against real
servers (TigerVNC's `Xvnc` with a terminal in it, and QEMU's built-in server) is written for the
automated tests on GitHub, where the two are installed for that job alone: it types into the
terminal and reads back what arrived, asks the X server where the pointer went, and compares
QEMU's screen with the screenshot QEMU takes of itself. It passed on Linux (Debian, and Ubuntu
24.04) and in the automated tests on GitHub. A libvirt guest's console was shown as a tile. RealVNC,
TightVNC, x11vnc and a controller's own VNC server have not been tried: see [Limits](https://qkvm.com/docs/limits).

An iDRAC's own VNC server (iDRAC Enterprise, port 5901 where it is switched on in the iDRAC, with the
VNC password set there) is a VNC server like any other: type `vncs://` where its SSL encryption is
on. That was built from Dell's documentation and has not been tried: whether that encryption is TLS
from the first byte, as `vncs://` speaks it, has not been seen.

### No KVM in front of it? A VNC server

A KVM shows a machine's screen from the moment it is switched on: its firmware setup, its boot
menu, a system that does not start. Where none of that is needed, and the machine only has to be
seen and used while its operating system runs (a desktop in an office, a test machine, a virtual
machine whose hypervisor gives it no console qKVM reads), a VNC server on the machine itself is
enough, and costs nothing. What it cannot do: it is a program of the operating system, so it is
not there before the system has started, nor once it has hung or shut down, and it has no power
button. A machine that has to be switched on, or seen while it starts, wants a KVM, its own
controller or Intel AMT.

Running one safely:

- **On your own network only.** Have the server listen on the machine's address in the LAN, or
  in a tailnet (Tailscale) or a VPN, and not on every address it has; and have the machine's
  firewall let its port (5900, or 5901) in from the wall's address, or from that network, alone.
  Never forward the port to the internet, nor open it there: VNC servers on the internet are
  found by scanners, and their passwords tried.
- **A password of its own.** Set a VNC password that is used for nothing else (VNC
  authentication reads its first eight characters only: see above), and give that one to the
  wall. A view-only password, or the server's view-only mode, takes keys and does nothing with
  them: leave it off where the wall is to type.
- **Encryption where the server offers it.** Plain VNC sends the pictures and the keys in the
  clear, and its password's answer can be tried against at leisure. A server that speaks TLS
  from the first byte is added with `vncs://`, and its certificate is remembered. Where a server
  encrypts only in a way qKVM does not speak (VeNCrypt, or a maker's own), carry the line in a
  tailnet or an SSH tunnel instead, with the server listening only where that ends (on the
  machine itself, for an SSH tunnel to it).
- **Say so to whoever sits there.** Where people work at the machine, use the server's setting
  that shows them, or asks them, when somebody connects, where it has one and that suits the
  place.
- **Keep it up to date**, as any program that listens on the network.

On Windows, TigerVNC, TightVNC or RealVNC run as a service; on Linux, x11vnc shows the desktop
that is on the screen and TigerVNC's server a desktop of its own. Of these, only TigerVNC's
server has been tried with qKVM (above). Then add it as the start of this chapter says: qKVM
already shows VNC servers, on a tile, enlarged and live with keyboard and mouse.
