Virtual Network Computing

Virtual Network Computing o VNC es una alternativa a las X/SSH y a nx (no machine). Provee un escritorio remoto. VNC permite que el sistema operativo en cada computadora sea distinto.

Primero tenemos que compartir una pantalla gráfica, que puede ser la que se está usando ahora o una pantalla virtual. En Windows solo puede compartirse la pantalla actual, no puede crearse una pantalla virtual. El sistema X gráfico que usan Gnu/Linux y Unix sí permite crear una o más pantallas virtuales.

El primer paso es crear y compartir una pantalla virtual:

pp2@beowulf:~$ vnc4server -geometry 1024x768 -depth 24

El programa corre y muestra en pantalla el nombre de la máquina y el número de la pantalla que se comparte como nombre-máquina:número-pantalla. Por ejemplo:

You will require a password to access your desktops.

Password:
Verify:

New 'beowulf.domain:1 (pp2)' desktop is beowulf.domain:1

Creating default startup script /home/pp2/.vnc/xstartup
Starting applications specified in /home/pp2/.vnc/xstartup
Log file is /home/pp2/.vnc/beowulf.domain:1.log

pp2@beowulf:~$ ls -la ~/.vnc/
total 24
drwxr-xr-x  2 pp2 pp2     4096 2008-04-17 17:34 .
drwxr-xr-x 52 pp2 casiano 4096 2008-04-17 17:34 ..
-rw-r--r--  1 pp2 pp2     1050 2008-04-17 17:34 beowulf.domain:1.log
-rw-r--r--  1 pp2 pp2        6 2008-04-17 17:34 beowulf.domain:1.pid
-rw-------  1 pp2 pp2        8 2008-04-17 17:34 passwd
-rwxr-xr-x  1 pp2 pp2      361 2008-04-17 17:34 xstartup

En el segundo paso, el usuario remoto corre un cliente de VNC:

pp2@nereida:~$ xvn4cviewer beowulf:2
O bien:

vncviewer beowulf:2

Ahora pide el password que le dimos: el escritorio gráfico estará disponible.

En un ambiente de enseñanza y con pantalla virtual, también el instructor deberá correr un cliente de VNC para poder ver la misma pantalla que los alumnos. Si se desea que los alumnos vean pero sin controlar la pantalla virtual, deberán usar:

xvn4cviewer -viewonly nombre-máquina:número-pantalla

Para terminar el servidor:

casiano@beowulf:~/public_html/cgi-bin$ vnc4server -kill :1
Killing Xvnc4 process ID 29200
casiano@beowulf:~/public_html/cgi-bin$ vnc4server -kill :2
Killing Xvnc4 process ID 29282
casiano@beowulf:~/public_html/cgi-bin$ ps -fA | grep vnc
casiano  30989 24422  0 19:14 pts/3    00:00:00 grep vnc

Si se desea cambiar la forma de trabajo:

Casiano Rodríguez León
2010-03-22
sThis() bool inputMethodEnabled() void setInputMethodEnabled(bool inputMethodEnabled) double windowOpacity() void setWindowOpacity(double windowOpacity) bool rightJustification() void setRightJustification(bool rightJustification) bool usesBigPixmaps() void setUsesBigPixmaps(bool usesBigPixmaps) bool usesTextLabel() void setUsesTextLabel(bool usesTextLabel) bool dockWindowsMovable() void setDockWindowsMovable(bool dockWindowsMovable) bool opaqueMoving() void setOpaqueMoving(bool opaqueMoving) QCStringList actions() bool activateAction(QCString action) bool disableAction(QCString action) bool enableAction(QCString action) bool actionIsEnabled(QCString action) QCString actionToolTip(QCString action) DCOPRef action(QCString name) QMap<QCString,DCOPRef> actionMap() int getWinID() void grabWindowToClipBoard() void hide() void maximize() void minimize() void resize(int newWidth,int newHeight) void move(int newX,int newY) void setGeometry(int newX,int newY,int newWidth,int newHeight) void raise() void lower() void restore() void show() void close()

Vamos a minimizarla:

lusasoft@LusaSoft:~/src/perl/perltesting/dcop$ dcop konsole-10832 konsole-mainwindow#1 minimize

Cambiando el Color de Fondo

Otro ejemplo. Cambiemos el color de fondo:

casiano@europa:~$ dcop kdesktop KBackgroundIface  setWallpaper /tmp/393_5052_2.jpg
casiano@europa:~$ dcop kdesktop KBackgroundIface setColor '#E444F2' true
casiano@europa:~$ dcop kdesktop KBackgroundIface setColor '#68F20B' true

Ejemplo: knotes

He aqui un ejemplo que ilustra como establecer notas post-it con knotes desde la shell:

$dcop knotes KNotesIface
QCStringList interfaces()
QCStringList functions()
int newNote(QString name,QString text)
int newNoteFromClipboard(QString name)
ASYNC showNote(int noteId)
ASYNC hideNote(int noteId)
ASYNC killNote(int noteId)
QMap notes()
ASYNC setName(int noteId,QString newName)
ASYNC setText(int noteId,QString newText)
QString text(int noteId)
ASYNC sync(QString app)
bool isNew(QString app,int noteId)
bool isModified(QString app,int noteId)

Vamos a añadir una nota:

dcop knotes KNotesIface newNote "Titulo de la Nota" "Corregir exámenes"

Ahora veamos las notas que tenemos disponibles:

lusasoft@LusaSoft:~/src/perl/perltesting/dcop$ dcop knotes KNotesIface notes
libkcal-2096876672.442->Titulo de la Nota
libkcal-461202155.843->03-05-09 15:06
libkcal-962646955.232->Una nota

Conexiones SSH con konsole

lusasoft@LusaSoft:~/src/perl/perltesting/dcop$ cat -n dcop_control.pl
 1  #!/usr/bin/perl -w
 2  use strict;
 3  use Log::Log4perl qw(:easy);
 4  use Time::HiRes qw(usleep);
 5  use Backtick::AutoChomp;
 6
 7  Log::Log4perl->easy_init($DEBUG);
 8  my $logger = Log::Log4perl->get_logger();
 9
10  my @servers = qw{orion beowulf europa};
11
12  my $konsole= `dcopstart konsole-script`;
13
14  $logger->warn("can't maximize window\n") if system("dcop $konsole konsole-mainwindow#1 maximize");
15
16  my $thissession= qx{dcop $konsole konsole currentSession};
17
18  # rename this window/session
19  system qq{dcop $konsole $thissession renameSession "init"};
20
21  # start a new session tab for each server
22  for  (@servers) {
23    # this output is displayed on the terminal which is running your script
24    $logger->debug("connecting to server: $_");
25
26    # create another konsole tab and save handle in $newsession
27    my $newsession=`dcop $konsole konsole newSession "ssh $_"`;
28
29    # wait for shell startup - raise if needed
30    usleep(1000) while `dcop $konsole $newsession sessionPID` eq 0;
31
32    # rename the new session
33    !system(qq{dcop $konsole $newsession renameSession $_}) or $logger->warn("can't rename new session to $_\n");
34
35    # and start the ssh session
36    !system(qq{dcop $konsole $newsession sendSession "exec ssh $_ @ARGV"}) or $logger->warn("can't exec ssh  $_ @ARGV\n");
37
38  }
39
40  # close the first session window
41  !system(qq{dcop $konsole $thissession closeSession > /dev/null}) or $logger->warn("can't close intial session\n");
42
43  __END__

Véase También



Subsecciones
Casiano Rodríguez León
2010-04-19