Convert Figma logo to code with AI

LibVNC logolibvncserver

LibVNCServer/LibVNCClient are cross-platform C libraries that allow you to easily implement VNC server or client functionality in your program.

1,112
484
1,112
81

Top Related Projects

High performance, multi-platform VNC client and server

VNC server app for Android that does not require root privileges.

11,507

VNC client web application

10,779

FreeRDP is a free remote desktop protocol library and clients

5,678

xrdp: an open source RDP server

Quick Overview

LibVNCServer is an open-source library that provides a framework for creating VNC (Virtual Network Computing) server and client applications. It allows developers to implement remote desktop functionality in their software, enabling users to view and control remote computers over a network connection.

Pros

  • Cross-platform compatibility (supports Windows, Linux, macOS, and more)
  • Supports multiple VNC protocols and encodings
  • Actively maintained with regular updates and bug fixes
  • Extensive documentation and examples available

Cons

  • Can be complex to set up and configure for beginners
  • Performance may vary depending on network conditions and encoding used
  • Some advanced features require additional dependencies
  • Security concerns if not properly configured (e.g., encryption, authentication)

Code Examples

  1. Creating a basic VNC server:
#include <rfb/rfb.h>

int main(int argc, char **argv)
{
    rfbScreenInfoPtr server = rfbGetScreen(&argc, argv, 800, 600, 8, 3, 4);
    server->frameBuffer = (char*)malloc(800 * 600 * 4);
    rfbInitServer(server);
    rfbRunEventLoop(server, -1, FALSE);
    return 0;
}
  1. Handling client connections:
static void clientgone(rfbClientPtr cl)
{
    printf("Client disconnected\n");
}

static enum rfbNewClientAction newclient(rfbClientPtr cl)
{
    cl->clientGoneHook = clientgone;
    return RFB_CLIENT_ACCEPT;
}

int main(int argc, char **argv)
{
    rfbScreenInfoPtr server = rfbGetScreen(&argc, argv, 800, 600, 8, 3, 4);
    server->newClientHook = newclient;
    // ... rest of the server setup
}
  1. Updating the framebuffer:
void updateFramebuffer(rfbScreenInfoPtr server)
{
    int i, j;
    for (i = 0; i < server->height; i++) {
        for (j = 0; j < server->width; j++) {
            server->frameBuffer[(i * server->width + j) * 4 + 0] = i % 256;
            server->frameBuffer[(i * server->width + j) * 4 + 1] = j % 256;
            server->frameBuffer[(i * server->width + j) * 4 + 2] = (i + j) % 256;
        }
    }
    rfbMarkRectAsModified(server, 0, 0, server->width, server->height);
}

Getting Started

To use LibVNCServer in your project:

  1. Install dependencies:

    sudo apt-get install libvncserver-dev
    
  2. Compile your program:

    gcc -o vnc_server vnc_server.c -lvncserver
    
  3. Run the VNC server:

    ./vnc_server
    
  4. Connect to the server using a VNC client (e.g., TightVNC, RealVNC) using the server's IP address and port 5900.

Competitor Comparisons

High performance, multi-platform VNC client and server

Pros of TigerVNC

  • More comprehensive VNC implementation with both server and viewer components
  • Better performance and optimizations for modern systems
  • Active development with regular updates and bug fixes

Cons of TigerVNC

  • Larger codebase and more complex architecture
  • Potentially higher resource usage due to additional features
  • Steeper learning curve for contributors and integrators

Code Comparison

TigerVNC

rfb::Region2D updateRegion;
updateRegion.assign_union(damage);
writer()->writeFramebufferUpdate(updateRegion, encodings);

libvncserver

rfbMarkRectAsModified(rfbScreen, x, y, w, h);
rfbProcessEvents(rfbScreen, usec_timeout);

TigerVNC uses a more object-oriented approach with C++ classes, while libvncserver employs a simpler C-style API. TigerVNC's code demonstrates more advanced region handling and encoding options, whereas libvncserver focuses on basic screen updates and event processing.

Both projects serve different use cases: TigerVNC is better suited for full-featured VNC implementations, while libvncserver is ideal for simpler, embedded VNC server integrations.

VNC server app for Android that does not require root privileges.

Pros of droidVNC-NG

  • Specifically designed for Android devices, offering better mobile optimization
  • Includes touch event handling and gesture support for mobile interfaces
  • Lighter weight and more focused on mobile VNC functionality

Cons of droidVNC-NG

  • Limited to Android platform, less versatile than libvncserver
  • Smaller community and potentially less frequent updates
  • May lack some advanced features present in the more comprehensive libvncserver

Code Comparison

libvncserver:

rfbNewFramebuffer(cl->screen, cl->scaledScreenBuffer,
                  cl->scaledScreen->width, cl->scaledScreen->height,
                  cl->screen->bitsPerPixel, cl->screen->samplesPerPixel,
                  cl->screen->bytesPerPixel);

droidVNC-NG:

public void onFramebufferUpdate(RfbProto rfb, int x, int y, int w, int h) {
    framebufferUpdated = true;
    handler.sendEmptyMessage(Constants.UPDATE);
}

The code snippets demonstrate the different approaches and languages used in each project. libvncserver uses C for low-level frame buffer manipulation, while droidVNC-NG employs Java for Android-specific implementations, focusing on event handling and UI updates.

11,507

VNC client web application

Pros of noVNC

  • Browser-based: Runs directly in web browsers without plugins
  • Cross-platform compatibility: Works on any device with a modern web browser
  • Easy deployment: No client-side installation required

Cons of noVNC

  • Performance: May have slightly higher latency compared to native VNC clients
  • Feature limitations: Some advanced VNC features might not be fully supported
  • Browser dependencies: Relies on browser technologies and may be affected by browser updates

Code Comparison

libvncserver (C):

rfbScreenInfoPtr rfbGetScreen(int* argc,char** argv,
 int width,int height,int bitsPerSample,int samplesPerPixel,
 int bytesPerPixel)

noVNC (JavaScript):

var rfb = new RFB({
    target: document.getElementById('vnc_canvas'),
    url: 'ws://example.com:5900'
});

Key Differences

  • Language: libvncserver is written in C, while noVNC is JavaScript-based
  • Usage: libvncserver is a server-side library, noVNC is a client-side application
  • Implementation: libvncserver provides low-level VNC functionality, noVNC offers a high-level, browser-friendly interface

Both projects serve different purposes in the VNC ecosystem, with libvncserver focusing on server-side implementation and noVNC providing a client-side, web-based solution.

10,779

FreeRDP is a free remote desktop protocol library and clients

Pros of FreeRDP

  • Supports multiple protocols (RDP, RemoteFX, etc.) beyond just VNC
  • More actively maintained with frequent updates and bug fixes
  • Offers better performance and security features for remote desktop connections

Cons of FreeRDP

  • Larger codebase and more complex to implement
  • Primarily focused on RDP, which may not be ideal for all use cases
  • Steeper learning curve for developers new to remote desktop protocols

Code Comparison

libvncserver:

rfbNewFramebuffer(cl, frameBuffer, width, height, 8, 3, 4);
rfbInitServer(cl);
rfbRunEventLoop(cl, -1, FALSE);

FreeRDP:

freerdp_context_new(&context);
freerdp_connect(context);
freerdp_loop(context);
freerdp_disconnect(context);
freerdp_context_free(context);

Both libraries provide similar functionality for establishing remote connections, but FreeRDP offers more comprehensive features and supports multiple protocols. libvncserver is more focused on VNC specifically, making it potentially easier to use for VNC-only implementations. FreeRDP's codebase is more extensive, reflecting its broader scope and feature set, while libvncserver's code is more concise and straightforward for VNC connections.

5,678

xrdp: an open source RDP server

Pros of xrdp

  • Supports the RDP protocol, which is widely used in Windows environments
  • Provides a more complete remote desktop solution, including audio and file transfer capabilities
  • Offers better integration with Windows clients and tools

Cons of xrdp

  • More complex setup and configuration compared to libvncserver
  • May have higher resource usage due to additional features
  • Less flexible for custom VNC-based implementations

Code Comparison

xrdp (C):

static int
xrdp_mm_process_login_response(struct xrdp_mm *self, struct stream *s)
{
    int rv;
    int code;
    char *reason;

    code = 0;
    rv = xrdp_sec_process_login_response(s, &code, &reason);
    // ... (additional code)
}

libvncserver (C):

rfbBool
rfbSendFramebufferUpdate(rfbClientPtr cl, sraRegionPtr updateRegion)
{
    rfbFramebufferUpdateMsg fu;
    sraRectangleIterator* i;
    sraRect rect;
    int nUpdateRegionRects;

    // ... (additional code)
}

Both projects are written in C and focus on remote desktop protocols. xrdp is more tailored for RDP and Windows compatibility, while libvncserver provides a flexible VNC implementation. The code snippets show different approaches to handling client connections and updates, reflecting their distinct protocol focuses.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

CI Build status Help making this possible Join the chat at https://gitter.im/LibVNC/libvncserver

LibVNCServer: A library for easy implementation of a VNC server. Copyright (C) 2001-2003 Johannes E. Schindelin

If you have a general question, it's best to ask in the community chat. If your concern is about a bug or feature request instead, please use the issue tracker.

If you already used LibVNCServer, you probably want to read NEWS.

What is it?

VNC is a set of programs using the RFB (Remote Frame Buffer) protocol. They are designed to "export" a frame buffer via net: you set up a server and can connect to it via VNC viewers. If the server supports WebSockets (which LibVNCServer does), you can also connect using an in-browser VNC viewer like noVNC.

It is already in wide use for administration, but it is not that easy to program a server yourself.

This has been changed by LibVNCServer.

Projects using it

The homepage has a tentative list of all the projects using either LibVNCServer or LibVNCClient or both.

RFB Protocol Support Status

Security Types

NameNumberLibVNCServerLibVNCClient
None1✔✔
VNC Authentication2✔✔
SASL20✔
MSLogon0xfffffffa✔
Apple ARD30✔
TLS18✔
VeNCrypt19✔
UltraVNC MSLogonII113✔

Encodings

NameNumberLibVNCServerLibVNCClient
Raw1✔✔
CopyRect2✔✔
RRE3✔✔
CoRRE4✔✔
Hextile5✔✔
Zlib6✔✔
Tight7✔✔
Ultra9✔✔
TRLE15✔
ZRLE16✔✔
ZYWRLE17✔✔
TightPNG-260✔

Transports

NameLibVNCServerLibVNCClient
RFB✔✔
Encrypted RFB via VeNCrypt✔
Encrypted RFB via AnonTLS✔
Websockets✔
Encrypted Websockets✔

How to build

LibVNCServer uses CMake, which you can download here or, better yet, install using your platform's package manager (apt, yum, brew, macports, chocolatey, etc.).

You can then build via:

mkdir build
cd build
cmake ..
cmake --build .

Crypto support in LibVNCClient and LibVNCServer can use different backends:

  • OpenSSL (-DWITH_OPENSSL=ON -DWITH_GCRYPT=OFF)
    • Supports all authentication methods in LibVNCClient and LibVNCServer.
    • Supports WebSockets in LibVNCServer.
  • Libgcrypt (-DWITH_OPENSSL=OFF -DWITH_GCRYPT=ON)
    • Supports all authentication methods in LibVNCClient and LibVNCServer.
    • Supports WebSockets in LibVNCServer.
  • Included (-DWITH_OPENSSL=OFF -DWITH_GCRYPT=OFF)
    • Supports only VNC authentication in LibVNCClient and LibVNCServer.
    • Supports WebSockets in LibVNCServer.

Transport Layer Security support in LibVNCClient and LibVNCServer can use:

  • OpenSSL (-DWITH_OPENSSL=ON -DWITH_GNUTLS=OFF)
  • GnuTLS (-DWITH_OPENSSL=OFF -DWITH_GNUTLS=ON)

For some more comprehensive examples that include installation of dependencies, see the Unix CI and Windows CI build setups.

Crosscompiling from Unix to Android

See https://developer.android.com/ndk/guides/cmake.html as a reference, but basically it boils down to:

mkdir build
cd build
cmake .. -DANDROID_NDK=<path> -DCMAKE_TOOLCHAIN_FILE=<path> -DANDROID_NATIVE_API_LEVEL=<API level you want>
cmake --build .

Crosscompiling from Linux to Windows

Tested with MinGW-w64 on Debian, which you should install via sudo apt install mingw-w64. You can make use of the provided toolchainfile. It sets CMake to expect (optional) win32 dependencies like libjpeg and friends in the deps directory. Note that you need (probably self-built) development packages for win32, the -dev packages coming with your distribution won't work. Also note that you'll need to put libwinpthread-1.dll in the build dir to run the examples. You can find this DLL on your Linux build machine via locate libwinpthread-1.dll.

mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-mingw32-linux.cmake ..
cmake --build .

Cutting a Release

How to use

See the LibVNCServer API intro documentation for how to create a server instance, wire up input handlers and handle cursors.

In case you prefer to learn LibVNCServer by example, have a look at the servers in the examples/server directory.

For LibVNCClient, examples can be found in examples/client.

Incorporating LibVNCServer/LibVNCClient into your build system

The install process installs pkg-config .pc files for LibVNCServer as well as LibVNCClient which you can use in your build system via the usual pkg-config --cflags libvncserver et al.

If using CMake, LibVNCServer versions > 0.9.13 provide CMake configure files so in your project's CMakeLists.txt, you can say:

find_package(LibVNCServer)
if(LibVNCServer_FOUND)
	# libs and headers location are now accessible via properties, but you only
	# need to add the respective export target to your project's target_link_libraries,
	# cmake will automatically add libs and headers
	# eg: add client (YOUR_PROJECT_TARGET being a placeholder for your real target -
	# it must be defined by add_executable or add_library):
	target_link_libraries(YOUR_PROJECT_TARGET LibVNCServer::vncclient)
	# add server:
	target_link_libraries(YOUR_PROJECT_TARGET LibVNCServer::vncserver)
endif()

Using Websockets

You can try out the built-in websockets support by starting the example server from the webclients directory via ../examples/example. It's important to not start from within the examples directory as otherwise the server program won't find its HTTP index file. The server program will tell you a URL to point your web browser to. There, you can click on the noVNC-Button to connect using the noVNC viewer git submodule (installable via git submodule update --init).

Using Secure Websockets

If you don't already have an SSL cert that's trusted by your browser, the most comfortable way to create one is using minica. On Debian-based distros, you can install it via sudo apt install minica, on MacOS via brew install minica.

Go to the webclients directory and create host and CA certs via:

cd webclients
minica -org "LibVNC" $(hostname)

Trust the cert in your browser by importing the created cacert.crt, e.g. for Firefox go to Options->Privacy & Security->View Certificates->Authorities and import the created cacert.crt, tick the checkbox to use it for trusting websites. For other browsers, the process is similar.

Then, you can finally start the example server, giving it the created host key and cert:

../examples/example -sslkeyfile $(hostname).key -sslcertfile $(hostname).crt

The server program will tell you a URL to point your web browser to. There, you can click on the noVNC-encrypted-connection-button to connect using the bundled noVNC viewer using an encrypted Websockets connection.

Achieving good performance on 'slow' links

If your client-server connection is sluggish because the link is 'slow', there are a few things to consider.

First off, you have to investigate whether your link has low throughput or high latency or both.

Tackling High Latency

On a high-latency link, try asking for framebuffer updates continously, as RFB is client-pull per default, not server-push. One example implementation can be found here and it definitely improves responsiveness.

There also is the ContinuousUpdates RFB extension, but that one is not supported by LibVNC (yet).

Tackling Low Throughput

If your link is low-throughput, you basically have to reduce the number of bytes that get sent per framebuffer update:

  • First off, you should have your client request a lossy encoding such as Tight. This already yields some huge savings.
  • Use a pixel format that represents a pixel with a smaller amount of bytes. For instance, you can switch from 24-bit true colour to 16-bit high colour or even a palleted colour mode. You can request a pixel format via the client or set a default (native) one in the server. With the latter approach, however, you very probably also have to change the way your framebuffer data gets written, so the first client-side one should be preferred.
  • Send a scaled-down version of your framebuffer. You can do the scaling in your application feeding data into LibVNCServer's framebuffer (would affect all clients) or let LibVNCServer do the work for you if your client requests a scaled screen via a SetScale or SetScaleFactor message (this is per-client scaling - UltraVNC viewers can request this).

Commercial Use

At the beginning of this project Dscho, the original author, would have liked to make it a BSD license. However, it is based on plenty of GPL'ed code, so it has to be a GPL.

The people at AT&T worked really well to produce something as clean and lean as VNC. The managers decided that for their fame, they would release the program for free. But not only that! They realized that by releasing also the code for free, VNC would become an evolving little child, conquering new worlds, making its parents very proud. As well they can be! To protect this innovation, they decided to make it GPL, not BSD. The principal difference is: You can make closed source programs deriving from BSD, not from GPL. You have to give proper credit with both.

Frequently Asked Questions

Our commercial product wants to make use of LibVNCServer to create our own VNC server and distribute. Will this be considered derivative work in the GPLv2 context?

Yes. Please note that while you would have to stick to the GPL for your program if you link to LibVNCServer/LibVNCClient, you do not have to make your code public in case you use the derivative work internally in your organisation, see https://www.gnu.org/licenses/gpl-faq.html#GPLRequireSourcePostedPublic

Does modifying LibVNCServer code or not make any difference in determining whether our VNC server will be considered derivative work?

No. By simply linking to LibVNCServer/LibVNCClient, your program becomes derivative work.

License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Contact