VNC in your browser through WebSockets, handled by Gevent


Reading on websockets the other day I ended in this article about websockets and vnc and it draw my attention immediately over the showmethedesktop project.

Now, given my interest on async servers and my recent interest on their implementation on python along with the rustiness of my perl I decided to try a reimplementation on async python as a way to introduce me to the gevent framework.

First impressions

  • It is actually feasible to draw a whole screen using just Javascript through canvas and (put/get)ImageData
  • Some browsers are remarkable faster than others doing this, chrome 15 has a 800×600 draw time of 0-1 msec while Firefox 7 has about 5-13 msec draw time
  • It is perfectly usable unless you want to play videos or something like that

Project

Available in github, comments and patches are welcome! still in development though.

How did I do it

Very quickly actually, thanks to python and gevent, and specially thanks to other projects I took and adapted code from, such as showmethedesktop, python-vnc-viewer and gevent-websocket.

  • Most of the html+javascript is just copied from showmethedesktop with some adaptations of my own
  • I forked gevent-websocket on bitbucket and implemented the new hybi WS protocol on it, it is actually the only thing that current firefox and chrome speak so there was no option there, I also introduced some other small changes
  • I copied all the rfb(Remote Frame Buffer, VNC protocol) implementation from python-vnc-viewer and then removed the twisted dependency and adapted everything to work on gevent.
  • Finally thanks to gevent I created the “main” of my app, really just a gevent app

Issues

Gevent and greenlet have some kind of incompatibility on python 2.7, requirements.txt had to include this version http://bitbucket.org/snaury/greenlet/get/tip.zip#egg=greenlet

Howto

git clone git://github.com/arkaitzj/wsvnc.git &&
cd wsvnc &&
virtualenv --no-site-packages sandbox &&
sandbox/bin/pip install -r requirements.txt &&
sandbox/bin/python wsvnc.py

4 Responses to VNC in your browser through WebSockets, handled by Gevent

  1. Jean-Paul Calderone says:

    > implemented the new hybi WS protocol on it

    Why? https://github.com/MostAwesomeDude/txws

    > removed the twisted dependency and adapted everything to work on gevent

    Why?

    • Chris Sears says:

      Perhaps because twisted is going out of style and gevent is the new hotness. But seriously, given the choice, I think most developers prefer gevent’s coroutine-based approach to python async code over Twisted’s deferred/callback model.

  2. Orb says:

    you type excruciatingly slow for a “developer” lol

  3. Jeffrey Gelens says:

    The latest stable version of gevent-websocket already supports everything what’s in your fork. So you can use that one instead ;)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: