You are on page 1of 46

VIRTUAL NETWORKING COMPUTING

A PROJECT REPORT

Submitted by

AVINASH

BRIJESH PATEL
ARUN
JITENDER KUMAR

BACHELOR OF TECHNOLGY
6TH SEMESTER
IN

COMPUTER SCIENCE AND ENGINEERING

MAHATMA GANDHI MISSION’S COLLEGE OF


ENGINEERING AND TECHNOLOGY NOIDA

UTTAR PRADESH TECHNICAL UNIVERSITY


APRIL 2010
UTTAR PRADESH TECHNICAL UNIVERSITY

BONAFIDE CERTIFICATE

Certified that this project report “ VIRTUAL NETWORK COMPUTING” is

the bonafide work of “AVINASH , BRIJESH PATEL , ARUN KUMAR ,

JITENDER KUMAR” who carried out the project work under my supervision.

SIGNATURE

Mrs Neelam Jain

SUPERVISOR

LECTURER

COMPUTER SCIENCE

COMPUTER SCIENCE DEPARTMENT

MAHATMA GANDHI MISSION’S


COLLEGE OF ENGINEERING AND
TECHNOLOGY
TABLE OF CONTENTS

CHAPTER NO. TITLE PAGE NO.

1. INTRODUCTION 1
1.1 Introduction 1

1.2 abstract 2

1.3 overview 5

1.4 getting started 21

2 SRS DOCUMENT 23

3 Implementation 24

4 Testing 25

5 coding 26

6 Snapshots 27

7. FUTURE SCOPE 20

8. LIST OF REFERENCES 21
1.ABSTRACT

VIRTUAL NETWORK COMPUTING


"Virtual Network Computing" is an application that is mainly intended for initiating and
controlling remote desktop with in a network. The application also provides a facility to
view and control the remote applications. Normally applications on a network can be
accessed and executed by users as per the permissions assigned by the administrator.
But unable to access the desktop. The "VNC" one such application that tries to provide
facilities to initiate specific applications on a remote machine to be executed.
The purpose of the VNC is to view the desktop, the processes and the services that are
running on a remote system on the network without being physically present there. The
"VNC" consists of mainly two modules.
• Te Remote Host(Server)
• The User(Client) Remote host:
The Remote Host is the server, which could be any machine on a network. This
machine is the one, which the user wants to retrieve. It runs the server module and
opens a TCP/IP connection. The server machine will be polling at this socket
connection looking for the client to connect. The User:
User, the client module, requests for a connection. When the connection is established
the remote desktop is displayed at the client module interface, we can access and
control the remote machines desktop from here.
1.INTRODUCTION:
"Virtual Network Computing" is a technology for remote desktop sharing. VNC was
created as an open source research project in the late 1990s. Since that time, several
mainstream remote desktop solutions have been created based on VNC. The original
development team produces the RealVNC package. Other popular derivatives include
Ultra VNC and TightVNC. VNC works similarly to the Remote Desktop application built
into newer versions of Microsoft Windows. Unlike Windows Remote Desktop, VNC runs
on older Windows computers, Linux/Unix and other non-Windows operating systems.
VNC applications, however, are generally regarded as slower and offering fewer
features and security options than Windows Remote Desktop. VIRTUAL NETWORK
COMPUTING:
"Virtual Network Computing" is a tool to access another system's desktop at your
machine. The Server module runs on the Remote machine and the Client module runs
at your machine. This tool helps to invoke the application at desktop of Remote machine
using the interface at your machine. The tool has feature of providing the color mode to
view the desktop at different color setting. In order to provide the quick data transfer rate
to the client machine the data send from the Remote Server machine is compressed.
Remote Desktop Viewer and controller System is mainly intended for those scenarios,
which runs on a client/server, Internet and Intranet worked environment.
The tool is implemented using TCP/IP network protocol, the server on the remote host
machine initiate the connection, and waits for the Client request. The client machines
specify the remote host address. When the connection is established the Client gets the
View of the Remote host desktop. The activities at the remote machine are refreshed at
the client at regular intervals. The information send over the network is compressed to
enable quick data transfer. For this the Client can select various compression modes.
This includes the Huffman's algorithm for data compression.
VNC stands for Virtual Network Computing. It is remote control software which allows
you to view and interact with one computer (the "server") using a simple program (the
"viewer") on another computer anywhere on the Internet. The two computers don't even
have to be the same type, so for example you can use VNC to view an office Linux
machine on your Windows PC at home. VNC is freely and publicly available and is in
widespread active use by millions throughout industry, academia and privately.
Overview-VNC:

VNC consists of two components. A server, which runs on the computer you want to
remotely access, and a viewer, which runs on the computer you are sitting in front of.
There are two important features of VNC:
• The server and the viewer may be on different machines and on types of computer.
The protocol which connects the server and viewer is simple, open, and platform
independent.
• No state is stored at the viewer. Breaking the viewer's connection to the server and
then reconnecting will not result in any loss of data. Because the connection can be
remade from somewhere else, you have easy mobility.
So to get started with VNC you need to run a server, and then connect to it with a
viewer. Networking:
VNC software requires a TCP/IP connection between the server and the viewer. This is
the standard networking protocol on LANs, WANs, broadband and dialup ISP. Each
computer has a unique IP address and may also have a name in the DNS. You will
need to know the IP address or name of the server when you connect a viewer to it.
Sometimes the IP address is fixed, and sometimes it is issued to you dynamically by
your ISP. If it is allocated dynamically, you might consider using a third party DNS
management service.
The VNC Protocol:
The VNC protocol is a simple protocol for remote access to graphical user interfaces. It
is based on the concept of a remote framebuffer or RFB. In the past we have tended to
refer to the VNC protocol as the RFB protocol, so you may have seen this term in other
publications. The protocol simply allows a server to update the framebuffer displayed on
a viewer. Because it works at the framebuffer level it is potentially applicable to all
operating systems, windowing systems and applications. This includes X/Unix,
Windows, and Macintosh, but might also include PDAs, and indeed any device with
some form of communications link. The protocol will operate over any reliable transport
such as TCP/IP.

This is truly a "thin-client" protocol: it has been designed to make very few
requirements of the viewer. In this way, clients can run on the widest range of hardware,
and the task of implementing a client is made as simple as possible.
Rectangular updates:
The display side of the protocol is based around a single graphics primitive: "put a
rectangle of pixel data at a given x, y position". This might seem an inefficient way of
drawing arbitrary user interface components. But because we have a variety of different
encoding schemes for the pixel data, we can select the appropriate scheme for each
rectangle we send, and make the most of network bandwidth, client drawing speed and
server processing speed.
The lowest common denominator is the so-called raw encoding, where the
rectangle is simply pixel data sent in left-to-right scan line order. All clients and servers
must support this encoding. However, the encodings actually used on any given VNC
connection can be negotiated according to the abilities of the server, the client, and the
connection between the two.
The copy rectangle encoding, for example, is very simple and efficient and can be
used when the client already has the same pixel data elsewhere in its frame buffer. The
server simply sends an X, Y coordinate giving the position from which the client can
copy the rectangle of pixel data. This means that operations such as dragging or
scrolling a window, which involve substantial changes to the screen, may only require a
few bytes. Most clients will support this encoding, since it is generally simple to
implement and saves bandwidth.
A typical workstation desktop has large areas of solid colour and of text. Some of our
most effective encodings take advantage of this by efficiently describing rectangles
consisting of one majority (background) colour and 'sub-rectangles' of different colours.
There are numerous other
Virtual network computing
possible schemes. We
might use a JPEG encoding for still images or MPEG for efficient transmission of
moving images. An encoding which uses some kind of caching of pixel data would be
good for rendering text, where the same character is drawn in the same font multiple
times. Subsequent occurrences of the same character would be encoded simply by
reference to the first occurrence.
Adaptive update protocol:
A sequence of these rectangles makes a framebuffer update (or simply update). An
update represents a change from one valid framebuffer state to another, so in some
ways is similar to a frame of video, but it is usually only a small area of the framebuffer
that will be affected by a given update. Each rectangle may be encoded using a
different scheme. The server can therefore choose the best encoding for the particular
screen content being transmitted and the network bandwidth available.
The update protocol is demand-driven by the client. That is, an update is only sent by
the server in response to an explicit request from the client. This gives the protocol an
adaptive quality. The slower the client and the network are, the lower the rate of
updates becomes. Each update incorporates all the changes to the 'screen' since the
last client request. With a slow client and/or network, transient states of the framebuffer
are ignored, resulting in reduced network traffic and less drawing for the client. This also
improves the apparent response speed.
Output protocol:
The input side of the protocol is based on a standard workstation model of a keyboard
and multi-button pointing device. Input events are sent to the server by the client
whenever the user presses a key or pointer button, or whenever the pointing device is
moved. These input events can also be synthesized from other non-standard I/O
devices.
Connection Setup and Shutdown:
When the connection between a client and a server is first established, the server
begins by requesting authentication from the client using a challenge-response scheme,
which typically results in the user being prompted for a password at the client end. The
server and client then exchange messages to negotiate desktop size, pixel format, and
the encoding schemes to be used. The client then requests an update for the entire
screen, and the session begins. Because of the stateless
Virtual network computing
nature of the client, either side can close the connection at any time without adverse
consequences.
VNC Clients:
Writing a VNC viewer is a simple task, as it should be for any thin-client system. It
requires only a reliable transport (usually TCP/IP), and a way of displaying pixels (either
directly writing to the framebuffer, or going through a windowing system). VNC clients
exist for all flavors of UNIX, Windows, Macintosh, and Java and for smaller handheld
appliances.
VNC Servers:
Writing a VNC server is slightly harder than writing a client for a number of reasons. The
protocol is designed to make the client as simple as possible, so it is usually up to the
server to perform any necessary translations. For example, the server must provide
pixel data in the format the client wants. There are servers UNIX, Windows and
Macintosh platforms A Unix machine can run a number of Xvnc servers for different
users, each of which represents a distinct VNC desktop. Each VNC desktop is like a
virtual X display, with a root window on which several X applications can be displayed.
The Windows server (WinVNC) is a little more difficult to create, because there are
fewer places to insert hooks into the system to monitor display updates, and a less
clearly-defined model of multi-user operation. Servers simply mirror the real display to a
remote client, which means that the server is not 'multi-user'. It does, however, provide
the primary user of a PC with remote access to their desktop
GETTING STARTED WITH VNC
VNC consists of two types of component. A server, which generates a display, and. a
viewer, which actually draws the display on your screen
To get started with VNC you need to run a server, and then connect to it with a viewer.
Get the packages for the platforms you use from the web and install them. The current
VNC software requires a TCP/IP connection between the server and the viewer.

Most people will be running either a Unix server or a Windows server, though similar
principles will apply to other platforms. The technology underlying the VNC system is a
simple protocol for remote access to graphical user interfaces. It works at the frame
buffer level and therefore applies to all operating systems, windowing systems, and
applications—indeed to any device with some form of communications link. The
protocol will operate over any reliable transport such as TCP/IP. The endpoint with
which the user interacts (that is, the display and/or
input devices) is called the VNC client or viewer. The endpoint where changes to the
frame buffer originate (that is, the windowing system and applications) is known as the
VNC server .VNC is truly a “thin-client” system. Its design makes very few requirements
of the client, and therefore simplifies the task of creating clients to run on a wide range
of hardware.
3.1 Adaptive Update
A set of rectangles of pixel data makes a frame buffer update(or simply, update). An
update represents a change from one valid frame buffer state to another. In this sense,
an update is similar to a frame of video. It differs, however, in that it usually affects only
a small area of the frame buffer. Each rectangle may be encoded using a different
scheme. The server can therefore choose the encoding most appropriate for the
particular screen content being transmitted and the available network bandwidth. The
update protocol is demand-driven by the client. That is, an update is only sent by the
server in response to an explicit request from the client. All screen changes since the
client’s last request are coalesced into a single update. This gives the protocol an
adaptive quality: the slower the client and the network, the lower the rate of updates. On
a fast network, for example, as the user drags a window across the screen it will move
smoothly, being drawn at all the intermediate positions. On a slower link—for example,
over a modem—the client will request updates less frequently, and the window will
appear at fewer of these positions. This means that the display will reach its final state
as quickly as the network bandwidth will allow, thus maximizing the speed of interaction.
3.2 Input
The input side of the VNC protocol is based on a standard workstation model of a
keyboard and multi button pointing device. The client sends input events to the server
whenever the user presses a key or pointer button, or moves the pointing device. Input
events can also be synthesized from other nonstandard I/O devices. On the Video tile,
for example, a pen-based handwriting recognition engine generates keyboard events.
3.3 Connection Setup and Shutdown
To establish a client-server connection, the server first requests authentication from the
client, using a challenge-response VNC server VNC viewer (client)VNC protocol
scheme; the client typically requires the user to enter a password at this point. The
server and client then exchange messages to negotiate desktop size, pixel format, and
encoding schemes. The client requests an update for the entire screen, and the session
begins. Because of the stateless nature of the client, either side can close the
connection at any time without adverse consequences
3.4 VNC Viewers
In day-to-day use, we prefer the more descriptive term viewer to the rather overloaded
word client. Writing a VNC viewer is a simple task, as indeed it should be for any thin
client system. It requires only a reliable
transport (usually TCP/IP), and a way of displaying pixels (either writing directly to the
frame buffer or going through a windowing system).We have written viewers for all the
networked display devices available at ORL. These include the Video tile (the original
VNC viewer), an X-based viewer (which runs on Solaris, Linux, and Digital Unix
workstations), a Win32viewer that runs on Windows NT and 95, and a Java applet that
runs on any Java-capable browser (including Sun’s Java Station). Members of our lab
use these viewers on a daily basis to access their personal computing environments.
3.4.1 Running a Viewer
You can now go to another machine and connect a viewer to the server. When you run
the viewer, you need to specify the name of the server and the number of the desktop.
If, for example, you have started a
server as display 2 on a machine called ‘snoopy’, you can start a viewer for it by typing:
vnc viewer snoopy:2
With the Windows viewer, you can run it from the command line, but you will more
typically run it from the VNC group on the Start Menu. In this case, you will be prompted
for the host name and display number:

Enter it and click OK, and you will be prompted for your password, after which you
should see the remote display.

If you are connecting to a Windows or Mac server, the display number will be 0, unless
you have explicitly changed it.
If the machine running the server does not have a proper DNS entry, you probably won’t
be able to use the name and will have to replace snoopy:2 with something like
192.168.1.2:2. You can get round this on most platforms by creating a ‘hosts’ file which
maps names onto IP addresses.
3.5VNC Servers
Writing a VNC server is slightly harder than writing a viewer. Because the protocol is
designed to make the client as simple as possible, it is usually up to the server to
perform any necessary translations (for example, the server must provide pixel data in
the format the client wants). We have written servers for our two main platforms, X (that
is, Unix)and Windows NT/95.The X-based server was the first one we developed. A
single Unix machine can run a number of VNC servers for different users, each
representing a distinct VNC desktop. Each desktop is like a virtual X display, with a root
window on which several X applications can appear. The Windows VNC server was a
little more difficult to create. Windows has fewer places to insert hooks into the system
to monitor display updates, and the model of multi user operation is less clearly defined.
Our current server simply mirrors the real display to a remote client, which means that
only a single VNC desktop is available from any one PC. The X-based server, the X
viewer, the Win32 server, andWin32 viewer can all fit on a single floppy disk. We have
also created “thin” servers which produce displays other than desktops, using a simple
toolkit. A “VNCCD player,” for example, generates a CD player user interface using
VNC directly without any reference to a windowing system or frame buffer. Such servers
can run on very simple hardware, and can be accessed from any of the standard VNC
viewers.
3.5.1 Running a Windows Server

Install the Windows server, WinVNC, by running the Setup program included in the
distribution. This will create a VNC group in your Start Menu. Install the default registry
settings using the option in the VNC group.
Run the WinVNC server. If this is the first time you’ve used WinVNC on this machine
you’ll be prompted to set a password, which you’ll need. when you connect to the
machine from a remote location. Normally you’ll want to leave the other options on their
default settings(Note that the default display number is 0 on a PC. You’ll need to specify
this to the viewer when you connect). Click OK and the server should be running. It will
install a small icon on the system tray, and by right-clicking on this you can control most
aspects of the server.

A variety of desktops being accessed from different viewers: (a) a Unix desktop from a
Windows viewer, (b) a Windows 95 desktop from an X viewer, © a Unix desktop from a
Java applet within Internet Explorer, and (d) a Windows desktop using Netscape on
Unix.
SRS DOCUMENT

Purpose
This specification document describes the capabilities that will be provided by the software
application ‘VIRTUAL NETWORK COMPUTING’ . It also states the various required
constraints by which the software will abide. The intended audience for this document are the
development team, testing team and the end users of this product.

Scope
The software product ‘VIRTUAL NETWORK COMPUTING’ will be used to control the server
host using the client host.

USER INTERFACE

At ORL, we have used VNC to add mobility to workstation


GUIs, where the concept of at least some form of remote interaction
is not new. But the protocol’s simplicity could allow it to
be used on a much wider range of hardware. Consumer electronics
devices, such as CD players, usually have a highly specialized
user interfacical display devices. This has traditionally prevented such interfaces
from being mobile in the VNC sense of the word.
But we think VNC’s usefulness can be extended so that
users could, for example,
n bring up the controls for their video recorder on a
mobile phone as they drive home from work,
n use a modem to dial a telephone answering machine and
reprogram it through a graphical interface,
n display their car stereo or GPS receiver as part of the
dashboard, regardless of the equipment brand installed.
At present, such functions require the displaying device to
have detailed knowledge of the remote system and to emulate
that system’s user interface or some alternative interface
that it deems appropriate. For example, you would need a
driver for your video recorder, which was designed for your
mobile phone’s operating system. A much simpler approach
would be to use the interface designed for and provided with
the remote device, but to interact with it locally.
For this we need a set of common “phonemes” with which
we can construct a variety of GUIs. This is the role that the
VNC protocol—or something very similar to it—can play. It
is simple enough to implement cheaply in consumer electronics
hardware, yet it can be used to describe the building
blocks of most modern user interfaces. With standards such
as IEEE-1394 Firewire, USB, and IrDA, we have the physical
interface to connect a variety of devices; with VNC, we can
add a standard for plug-and-play user interfaces. Imagine
walking up to any workstation, connecting your PDA to the
USB port, and having the PDA applications instantly available
on the workstation screen, or plugging your PDA into
your car and having the engine management unit display servicing
information on the PDA’s screen. And imagine that
this works for any workstation, any PDA, any car.
The engine management example illustrates an important
point: A standardized GUI protocol allows devices that have
no physical display of their own to provide graphical information
when such a display becomes available to them. Your PDA
could, perhaps, shrink to the size of a pen if it could access a
display and keyboard through an IrDA link. And yet this
“microPDA” could still display PowerPoint-style presentations
when in the vicinity of an LCD projection panel or a large TV.
This model is very similar to the Web, where services
without an I/O capability of their own wait for a user to provide
one in the form of a Web browser. The success of this
strategy has led to embedding HTTP daemons in printers,
switches, routers, and other devices. But to be a Web server,
a device must at least have a TCP stack and an IP address.
And to be a Web browser requires at least the ability to render
fonts and parse HTML.
In contrast, VNC requires only a reliable transport medium
and the simplest of displaHTML will generally require the transmission of fewer bytes
than its VNC equivalent, the latter is infinitely more flexible.y capabilities. And while a page ofe
and typically employ customized phys-HTML will generally require the transmission of fewer
bytes
than its VNC equivalent, the latter is infinitely more flexible.
HARDWARE REQUIREMENTS

 Intel Processor.
 Two PC belonging to same network connection.
 Hard Disk : Above 1GB.

SOFTWARE REQUIREMENTS

 16 MB RAM.
 Operating System (Windows 9x or later).
 JVM
IMPLEMENTATION
INSTALLATION:
Running a Windows server:
Installing the Windows server, WinVNC, should create a RealVNC group in your Start...
menu. Run the VNC server.

If this is the first time you've used a VNC server on this machine you'll be prompted to
set a password, which you'll need when you connect to the machine from a remote
location. A small icon will appear in the system tray, and by right-clicking on this you can
control most aspects of the server.

Options... H
Add New Client Disconnect Clients;

Close VNC Server About...

16:19

The IP address of the computer running the VNC server can be found by hovering over
the tray icon in the system tray. Unless this computer has a DNS name, you will need to
specify this number to the viewer when you connect.

VNC Server (Service):192.168.0.103,172.16.76.1,172.16.209.1


«V2<YVS 17:33
r
You can now go to another machine and connect a viewer to the server.

Running a viewer:
You can run the Windows viewer the RealVNC group on the Start... menu.
In this case, you will be prompted for the host name (VNC server name) and display
number:
VNC Viewer : Connection Details

V9
About.

Server: | my host, mydomain. cor~ ~~*\


OK
Encryption: [Always Off I Options...
Cancel

Enter it and click OK, and you will be prompted for your password, after which you
should see the remote display. If you are connecting to a Windows or Mac server, the
display number will be 0 unless you have explicitly changed it, and can be omitted. You
can run the viewer on Unix and Windows by typing at the command line: vncviewer
snoopy: 2
You need to specify the name of the VNC server and the number of the desktop. If, for
example, you have started a server as display 2 on a machine called 'snoopy'.
Remember that if you are connecting to a Windows or Mac server, the display number
will be 0 unless you have explicitly changed it, and can be omitted. If the machine
running the server does not have a DNS entry, you probably won't be able to use the
name and will have to replace snoopy with its IP address, for example something that
looks like 123. 456. 78. 9.
SOURCE CODE

Jvncclient.java

import java.awt.Color;

import java.awt.FlowLayout;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JLabel;

import java.awt.*;

import javax.swing.JPanel;

import java.awt.event.*;

import java.net.Socket;

import java.net.UnknownHostException;

import java.io.ObjectInputStream;

import java.io.PrintWriter;

import javax.swing.JOptionPane;

import javax.swing.SwingUtilities;

public class JVNCclient extends JFrame implements MouseWheelListener

private JLabel screen;


private ObjectInputStream in;

private PrintWriter out;

private ScreenThread screenThread;

private ImageIcon i;

private Socket s;

private boolean stopped = false;

public JVNCclient()

int WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width;

int HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height;

setTitle("Virtual Network Computing");

setBackground(Color.white);

screen = new JLabel();

getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));

getContentPane().add(screen);

resize(WIDTH,HEIGHT-10);

addMouseListener(new MyMouseAdapter(this));

addMouseMotionListener(new MyMouseMotionAdapter(this));

addKeyListener(new MyKeyAdapter(this));

addWindowListener(new WindowAdapter()

public void windowClosing(WindowEvent we)

{
stopped = true;

screenThread.stopRunning();

sendAndUpdate(JVNCconstant.CLOSE,0,0);

System.exit(0);

});

String serverName = JOptionPane.showInputDialog(this, "Enter Server name :", "Server",


JOptionPane.INFORMATION_MESSAGE);

try

s = new Socket(serverName.trim(), 1166);

if (s==null)

System.out.println("No I/O");

System.exit(0);

else

in = new ObjectInputStream(s.getInputStream());

out = new PrintWriter(s.getOutputStream());

screenThread = new ScreenThread();

}
catch (Exception ex)

JOptionPane.showMessageDialog(null,"Server not found on PORT number 1166");

System.exit(0);

public void updateScreen(final ImageIcon i)

javax.swing.SwingUtilities.invokeLater(new Runnable()

public void run()

screen.repaint();

screen.setIcon(i);

});

private void sendAndUpdate(int type,int arg1, int arg2)

String s = "" + type + "|" + arg1 + "|" + arg2;


out.println(s);

out.flush();

class MyMouseAdapter extends MouseAdapter

JVNCclient jvnc;

public MyMouseAdapter(JVNCclient jvnc)

this.jvnc = jvnc;

public void mousePressed(MouseEvent e)

sendAndUpdate(JVNCconstant.MOUSE_PRESS, e.getX(),e.getY());

public void mouseReleased(MouseEvent e)

sendAndUpdate(JVNCconstant.MOUSE_RELEASE,0,0);

class MyMouseMotionAdapter extends MouseMotionAdapter

JVNCclient jvnc;

public MyMouseMotionAdapter(JVNCclient jvnc)

{
this.jvnc = jvnc;

public void mouseDragged(MouseEvent e)

sendAndUpdate(JVNCconstant.MOUSE_MOVE, e.getX(), e.getY());

public void mouseMoved(MouseEvent e)

sendAndUpdate(JVNCconstant.MOUSE_MOVE,e.getX(), e.getY());

public void mouseWheelMoved(MouseWheelEvent e)

sendAndUpdate(JVNCconstant.MOUSE_WHEEL,e.getScrollAmount(),0);

class MyKeyAdapter extends KeyAdapter

JVNCclient jvnc;

public MyKeyAdapter(JVNCclient jvnc)

this.jvnc = jvnc;

}
public void keyPressed(KeyEvent ke)

int key;

key = ke.getKeyCode();

if(key==ke.VK_ENTER)

sendAndUpdate(JVNCconstant.KEY_PRESS_EVENTS,ke.VK_ENTER,0);

else if(key==ke.VK_F1)

sendAndUpdate(JVNCconstant.KEY_PRESS_EVENTS,ke.VK_F1,0);

else if(key==ke.VK_ESCAPE)

sendAndUpdate(JVNCconstant.KEY_PRESS_EVENTS,ke.VK_ESCAPE,0);

public static void main(String argv[])

JVNCclient f = new JVNCclient();

f.setVisible(true);

f.show();

private class ScreenThread implements Runnable

Thread t;

private boolean keepRunning;

ScreenThread()

keepRunning = true;
t = new Thread(this,"Screen Thread");

t.start();

public void run()

while (keepRunning)

try

if(stopped ==false)

if((i = (ImageIcon)in.readObject())!=null)

updateScreen(i);

Thread.sleep(1000);

i=null;

else

keepRunning = false;

in.close();

}
catch(InterruptedException e)

System.out.println("Thread Interrupted");

catch(OutOfMemoryError e)

e.toString();

JOptionPane.showMessageDialog(null,"JVM can not able to


allocate Memory");

System.exit(0);

catch (ClassNotFoundException ex)

ex.printStackTrace();

catch (Exception ex)

ex.printStackTrace();

JOptionPane.showMessageDialog(null,"Server is stoped");

System.exit(0);

public void stopRunning()

{
keepRunning = false;

Jvncconstant.java

public class JVNCconstant


{
public static final int CLOSE = 0;
public static final int MOUSE_MOVE = 1;
public static final int MOUSE_PRESS = 2;
public static final int MOUSE_RELEASE = 3;
public static final int MOUSE_WHEEL = 4;
public static final int KEY_PRESS = 6;
public static final int KEY_RELEASE = 7;
public static final int KEY_TYPED = 5000;
public static final int KEY_PRESS_EVENTS = 12345;
}
Jvncserver.java
import java.awt.AWTException;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import java.awt.event.*;
public class JVNCserver
{
private final int WIDTH =
Toolkit.getDefaultToolkit().getScreenSize().width;
private final int HEIGHT =
Toolkit.getDefaultToolkit().getScreenSize().height;
private final Rectangle screenRect = new Rectangle(0, 0,
WIDTH, HEIGHT);
public Socket socket;
public ServerSocket s;
private CaptureThread capturethread;
private CaptureEvents captureevents;
private Robot robot;
private ObjectOutputStream out;
private BufferedReader in;
private BufferedImage i;
Image image;
public static void main(String arg[])
{
JVNCserver s = new JVNCserver();
}
public JVNCserver()
{
try
{
s = new ServerSocket(1166);
socket = s.accept();
System.out.println("Server Started");
out = new
ObjectOutputStream(socket.getOutputStream());
in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
robot = new Robot();
capturethread = new CaptureThread();
captureevents = new CaptureEvents();
}
catch (IOException ex)
{
ex.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(null,"server
is stop");
}
}
public void sendImage() throws IOException
{
i = robot.createScreenCapture(screenRect);

image = i.getScaledInstance(WIDTH, HEIGHT-60,


Image.SCALE_SMOOTH);
out.writeObject(new ImageIcon(image));
i.flush();
image.flush();
out.flush();
}
private class CaptureThread implements Runnable
{
private volatile boolean keepRunning;
Thread thread;
CaptureThread()
{
thread = new Thread(this,"Capture Thread");
keepRunning = true;
thread.start();
}
public void run()
{
while (keepRunning)
{
try
{
sendImage();
Thread.currentThread().sleep(8000);
//Thread.currentThread().sleep(20000);
}
catch(InterruptedException e1)
{
System.out.println("Thread Stop");
}
catch (IOException ex)
{
ex.printStackTrace();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"server is stoped");
}
}
}
public void stopRunning()
{
keepRunning = false;
}
}
private class CaptureEvents implements Runnable
{
private volatile boolean keepRunning;
Thread thread;
private int HY = HEIGHT / 2;
int y;
CaptureEvents()
{
thread = new Thread(this,"Capture Events");
keepRunning = true;

thread.start();
}

public void run()


{
while (keepRunning)
{
try
{
if (in!=null)
{
String e = (String)in.readLine();

if (e!=null)
{
//System.out.println(e);
int eventType =
Integer.parseInt(e.substring(0, e.indexOf("|")));
int arg1 =
Integer.parseInt(e.substring(e.indexOf("|")+1, e.lastIndexOf("|")));
int arg2 =
Integer.parseInt(e.substring(e.lastIndexOf("|")+1));
if(eventType==JVNCconstant.CLOSE)
{
keepRunning = false;
in.close();
out.close();
return;
}
if(arg2 < HY)
y = arg2 - 20;
else if(arg2 > HY)
y = arg2 + 21;
if (eventType == JVNCconstant.MOUSE_MOVE)
robot.mouseMove(arg1,y);
else if (eventType == JVNCconstant.MOUSE_PRESS)
{
robot.mousePress(InputEvent.BUTTON1_MASK);
}
else if (eventType==JVNCconstant.MOUSE_RELEASE)

robot.mouseRelease(InputEvent.BUTTON1_MASK);
else if(eventType== JVNCconstant.MOUSE_WHEEL)
robot.mouseWheel(arg1);
else if(eventType == JVNCconstant.KEY_PRESS_EVENTS)
{
switch(arg1)
{
case KeyEvent.VK_ENTER:

robot.keyPress(KeyEvent.VK_ENTER);
break;
case KeyEvent.VK_F1:

robot.keyPress(KeyEvent.VK_F1);
break;
case KeyEvent.VK_ESCAPE:

robot.keyPress(KeyEvent.VK_ESCAPE);
break;
}
}
}
}
else
System.out.println("In empty");

//Thread.currentThread().sleep(50);
}
/*catch(InterruptedException e)
{
System.out.println("Thread Stop");
}*/
catch(SocketException ex)
{
ex.printStackTrace();

JOptionPane.showMessageDialog(null,"Client is stopped");
break;
}
catch (IOException ex)
{
ex.printStackTrace();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Server is stop");

}
}
}

public void stopRunning()


{
keepRunning = false;
}
}
}
RobotCheck.java

import java.awt.Robot;
import java.awt.event.*;
import java.awt.*;

class RobotCheck
{
public static void main(String argv[])
{
int WIDTH =
Toolkit.getDefaultToolkit().getScreenSize().width;
int HEIGHT =
Toolkit.getDefaultToolkit().getScreenSize().height;
try
{
System.out.println(WIDTH +" " + HEIGHT);
Robot robot = new Robot();
robot.mousePress(InputEvent.BUTTON1_MASK);
System.out.println(KeyEvent.VK_ENTER);
System.out.println(KeyEvent.VK_F1);
//robot.keyPress(KeyEvent.VK_ENTER);
//robot.mouseMove(12,555);
}
catch(Exception e)
{
}
}
}

ACTIVITY DIAGRAM FOR SERVER


Start Server

Is server capable to send desktop


No

Yes
Capture Desktop
Display Error Message

Send Desktop Screen

Receives Events From Client

Send Updated Screen (Image)

Client: The Client side is that machine from where the user can operate server/remote machine.
Server: Server side acts as the remote machine and is controlled by the client machine.

TESTING AND EVALUATION


A VNC system consists of a client, a server, and a communication protocol.

 The VNC server is the program on the machine that shares its screen. The
server passively allows the client to take control of it.

 The VNC client (or viewer) is the program that watches, controls, and interacts
with the server. The client controls the server.

 The VNC protocol (RFB) is very simple, based on one graphic primitive from
server to client ("Put a rectangle of pixel data at the specified X,Y position") and
event messages from client to server.

To establish a client-server connection, the server first requests authentication


from the client, using a challenge-response scheme; the client typically requires the
user to enter a password at this point.

The server and client then exchange messages to negotiate desktop size, pixel format,
and encoding schemes.

The client requests an update for the entire screen, and the session begins.
Because of the stateless nature of the client, either side can close the connection at any
time without adverse consequences.
A variety of desktops being accessed from different viewers:

(a) a Unix desktop from a Windows viewer,


(b) a Windows 95 desktop from an X viewer,
(c) a Unix desktop from a Java applet within Internet Explorer, and
(d) a Windows desktop using Netscape on Unix.
FUTURE SCOPE

We are now building VNC software for a variety of desktop platforms, but it would
not be difficult to make remote access practical for a wider range of devices. We can
envisage cheap hardware that might, for example, drive a 7- segment LCD and also
emit a VNC equivalent over a USB or RS232 link.

The VNC commands to draw and erase each segment could be stored as a
sequence of bytes in a small amount of ROM and sent over a communications link
when the segment is lit or switched off. Hardware such as this, if made in quantity, could
be very cheap and could allow for mobility of much more than just a conventional
“desktop.”

If built into television sets, VNC viewers could allow them to act as displays for a
very wide range of devices—including, of course, the PC at the office.

In future,

 processing speed of the software can be increased.

 Photos can be send after compressing.

 Desktops of various machines can be seen simultaneously on a single computer.


CONCLUSION
In this project, i.e. Virtual Network Computing (VNC), the area of virtual networks
& remote terminal access has been explored.

VNC is reasonably fast. It allows users to access remote terminals and that too at
a very good speed. It allows user to simultaneously use two terminals.

You can use VNC as general-purpose remote control product, which allows
handling of multiple terminals from a single terminal. It is very useful in all places where
people working at different terminals need to access other terminals for various
purposes.

For example, the support and maintenance department in companies can use
this system to update various terminals at various locations from a single point.
REFERENCES

 Complete reference (5th Edition)- Herbert Schildt

 How to write program using swing- Detiel and Daita.l

You might also like