Top Banner
VIRTUAL NETWORKING COMPUTING A PROJECT REPORT Submitted by AVINASH BRIJESH PATEL ARUN JITENDER KUMAR BACHELOR OF TECHNOLGY 6 TH SEMESTER IN COMPUTER SCIENCE AND ENGINEERING MAHATMA GANDHI MISSION’S COLLEGE OF ENGINEERING AND TECHNOLOGY NOIDA
57
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Project

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

Page 2: Project

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

Page 3: Project

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

Page 4: Project

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.

Page 5: Project

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.

Page 6: Project

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 fewrequirements 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

Page 7: Project

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 therectangle 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 beused 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 otherVirtual network computing possible schemes. Wemight 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:

Page 8: Project

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 statelessVirtual 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

Page 9: Project

GETTING STARTED WITH VNCVNC consists of two types of component. A server, which generates a display, and. a viewer, which actually draws the display on your screenTo 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 UpdateA 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 InputThe 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,

Page 10: Project

for example, a pen-based handwriting recognition engine generates keyboard events.3.3 Connection Setup and ShutdownTo 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 consequences3.4 VNC ViewersIn 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 ViewerYou 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 aserver as display 2 on a machine called ‘snoopy’, you can start a viewer for it by typing:vnc viewer snoopy:2With 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

Page 11: Project

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.

Page 12: Project

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 workstationGUIs, where the concept of at least some form of remote interactionis not new. But the protocol’s simplicity could allow it tobe used on a much wider range of hardware. Consumer electronicsdevices, such as CD players, usually have a highly specializeduser interfacical display devices. This has traditionally prevented such interfacesfrom being mobile in the VNC sense of the word.But we think VNC’s usefulness can be extended so thatusers could, for example,n bring up the controls for their video recorder on amobile phone as they drive home from work,n use a modem to dial a telephone answering machine andreprogram it through a graphical interface,n display their car stereo or GPS receiver as part of thedashboard, regardless of the equipment brand installed.At present, such functions require the displaying device tohave detailed knowledge of the remote system and to emulatethat system’s user interface or some alternative interfacethat it deems appropriate. For example, you would need adriver for your video recorder, which was designed for yourmobile phone’s operating system. A much simpler approachwould be to use the interface designed for and provided withthe remote device, but to interact with it locally.For this we need a set of common “phonemes” with whichwe can construct a variety of GUIs. This is the role that the

Page 13: Project

VNC protocol—or something very similar to it—can play. Itis simple enough to implement cheaply in consumer electronicshardware, yet it can be used to describe the buildingblocks of most modern user interfaces. With standards suchas IEEE-1394 Firewire, USB, and IrDA, we have the physicalinterface to connect a variety of devices; with VNC, we canadd a standard for plug-and-play user interfaces. Imaginewalking up to any workstation, connecting your PDA to theUSB port, and having the PDA applications instantly availableon the workstation screen, or plugging your PDA intoyour car and having the engine management unit display servicinginformation on the PDA’s screen. And imagine thatthis works for any workstation, any PDA, any car.The engine management example illustrates an importantpoint: A standardized GUI protocol allows devices that haveno physical display of their own to provide graphical informationwhen such a display becomes available to them. Your PDAcould, perhaps, shrink to the size of a pen if it could access adisplay and keyboard through an IrDA link. And yet this“microPDA” could still display PowerPoint-style presentationswhen in the vicinity of an LCD projection panel or a large TV.This model is very similar to the Web, where serviceswithout an I/O capability of their own wait for a user to provideone in the form of a Web browser. The success of thisstrategy 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 renderfonts and parse HTML.In contrast, VNC requires only a reliable transport mediumand the simplest of displaHTML will generally require the transmission of fewer bytesthan 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 bytesthan its VNC equivalent, the latter is infinitely more flexible.

Page 14: Project

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

Page 15: Project

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... HAdd 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:33r 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.

Page 16: Project

In this case, you will be prompted for the host name (VNC server name) and display number:VNC Viewer : Connection Details

V9About.

Server: | my host, mydomain. cor~ ~~*\OKEncryption: [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: 2You 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.

Page 17: Project

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;

Page 18: Project

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)

{

Page 19: Project

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();

}

}

Page 20: Project

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;

Page 21: Project

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)

{

Page 22: Project

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;

}

Page 23: Project

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;

Page 24: Project

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();

}

}

Page 25: Project

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()

{

Page 26: Project

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

Page 27: Project

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;

Page 28: Project

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

{

Page 29: Project

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");

}

}

Page 30: Project

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();

}

Page 31: Project

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)

{

Page 32: Project

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();

Page 33: Project

}

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));

Page 34: Project

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)

Page 35: Project

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

Page 36: Project

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)

{

Page 37: Project

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[])

Page 38: Project

{

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

Page 39: Project

Start Server

Is server capable to send desktopNo

Yes

Capture Desktop

Send Desktop Screen

Receives Events From Client

Send Updated Screen (Image)

Display Error Message

Client: The Client side is that machine from where the user can operate server/remote machine.

Page 40: Project

Server: Server side acts as the remote machine and is controlled by the client machine.

TESTING AND EVALUATION

Page 41: Project

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.

Page 42: Project

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.

Page 43: Project

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.

Page 44: Project

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.

Page 45: Project

REFERENCES

Complete reference (5th Edition)- Herbert Schildt

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

Page 46: Project