Final
Final
1. PROJECT OVERVIEW
1.1 Introduction
In today’s era, with the advent of new technologies, the world is getting smaller day by day.
People earlier had to travel all the way from one place to another to get their job done. But
with the introduction of computers and basically networking, people now can do their jobs
easily as well as stay connected. A computer network provides us with many such facilities
one of which is remote desktop control. Remote desktop program enables a network
administrator to work on any computer in the local area network (Intranet) or connected to
the Internet. Through Remote desktop a lot of tasks become possible such as remotely taking
control of a user's desktop to fix the problem and making the necessary changes. With its
help we will be able to see and work with the remote computer as if it is your own local
machine. Hence even if we are not capable of being in a certain place at a certain time,
distance doesn’t matter. No matter where we are, we can easily access the remote computer
from anywhere and get our job done.
Our program gives the user an interface by which Remote communication otherwise Remote
Desktop is easily accessible. To run a Remote Desktop, we run the server in the PC we wish
to access and a client application in the PC through which we wish to access the server.
Moreover, to allow only authorized users to run the server, authentication of the user starting
of the server is also made.
2
1.2 Objectives
The main objectives of our project “Remote Desktop” regarding the access of remote server are
as follows :
To allow a user to connect one computer to another remotely and access as well as handle
all its files.
To perform some important operations on remote computer, for example: startup and
shutdown of local applications.
To use own keyboard and mouse to control the remote computer from anywhere.
To enable file transfer between the remote and local computers.
To develop a user-friendly interface via fully prepared GUI.
To develop professionalism in software development and to improve skills of group
work.
The software tools that we used in our project can be listed as:
2. LITERATURE REVIEW
2.1 Network
2.1.1 Ports
Virtual ports are part of TCP/IP networking. The modern computers of today are designed to do
several different work at once. This is accomplished through ports. Each computer with an IP
address has several thousand logical ports. These ports allow software applications to share
hardware resources without interfering with each other. These are purely abstraction in the
computer’s memory and do not represent anything physical like a serial or parallel port. Each
port is identified by a number from 1 to 65,535.Each port can be allocated to a particular service.
For example the HTTP service, which is used by the Web, generally runs on port 80: we say that
a web server listens on port 80 for incoming connections. When a data is sent to a web server on
a particular machine at a particular IP address, it is also sent to a particular port (usually port 80)
on that machine. The receiver checks each packet it sees for the port and sends the data to any
programs that are listening to the specified port. This is how different types of traffic are sorted
out. Port numbers from 1 to 1023 are reserved for well-known services such as finger, FTP,
HTTP, and email. On UNIX operating systems, only programs running as root can receive data
from these ports, but all programs may send data to them. On Windows and the Mac, including
Windows NT, any program may use these ports without special privileges.
5
2.1.2 Protocols
A protocol is a set of rules that govern data communication. It represents the agreement between
the communicating parties on how communication is to proceed. Protocol is a very important
part of a computer network that enables proper data transmission among the network
components. There are many different protocols defining different aspects of network
communication. For example, the Hypertext Transfer protocol (HTTP) defines how web
browsers and servers communicate.
An Internet Protocol (IP) address is a numerical label that is assigned to devices participating in a
computer network that uses the Internet Protocol for communication between its nodes. A
computer’s IP address gives the internet routing protocols the unique information they need to
route packets of information on our desktop from anywhere across the Internet.
Java Robot Class is used to generate native system input events for the purposes of test
automation, self-running demos, and other applications where control of the mouse and keyboard
is needed. Once we get the control, we can do any type of operation related to mouse and
keyboard through our java code .In addition to controlling mouse clicks and keyboard presses,
6
Robot can also be used to do screen captures. The primary purpose of Robot is to facilitate
automated testing of Java platform implementations.
Using the class to generate input events differs from posting events to the AWT event queue or
AWT components in that the events are generated in the platform's native input queue. For
example, Robot.mouseMove will actually move the mouse cursor instead of just generating
mouse move events.
Some of the key features offered by the Robot class that we have implemented are as follows:
iii) Simulate/perform a screen capture - "Creates an image containing pixels read from the
screen. This image does not include the mouse cursor."
iv) Get pixel color - Gets the color of the pixel at a given screen co-ordinate.
2.3 Thread
A thread is a thread of execution in a program. Most programs written today run as a single
thread causing problems when multiple events or actions need to occur at the same time. Let's
say, for example, a program is not capable of drawing pictures while reading keystrokes. The
7
program must give its full attention to the keyboard input lacking the ability to handle more than
one event at a time. The ideal solution to this problem is the seamless execution of two or more
sections of a program at the same time. Threads allow us to do this. Thread-based multitasking
has multiple threads running at the same time (that is, multiple parts of a program running
concurrently). The Java run-time environment manages threads, unlike in process-based
multitasking where the operating system manages switching between programs. Threads are
processed asynchronously, that is one thread can pause while other threads continue to process.
Multithreading occurs asynchronously, meaning one thread executes independently of the other
threads. In this way, threads don’t depend on each other’s execution. In contrast, processes that
run synchronously depend on each other. That is, one process waits until the other process
terminates before it can execute.
Java's multithreading support is centered around the java.lang.Thread class. The Thread class
provides the capability to create objects of class Thread, each with its own separate flow of
control. The Thread class encapsulates the data and methods associated with separate threads of
execution and allows multithreading to be integrated within the object-oriented framework.
Java provides two approaches to creating threads. In the first approach, we can create a subclass
of class Thread and override the run() method to provide an entry point into the thread's
execution. When we create an instance of our Thread subclass, weinvoke its start() method to
cause the thread to execute as an independent sequence of instructions. The start() method is
inherited from the Thread class. It initializes the Thread object using our operating system's
multithreading capabilities and invokes the run() method.
2.4 Sockets
A socket is one end-point of a two-way communication link between two programs running on
the network. Socket classes are used to represent the connection between a client program and a
server program.The socket associates the server program with a specific hardware port on the
machine where it runs so any client program anywhere in the network with a socket associated
with that same port can communicate with the server.
8
Normally, a server runs on a specific computer and has a socket that is bound to a specific port
number. The server just waits, listening to the socket for a client to make a connection request.
On the client-side: The client knows the hostname of the machine on which the server is running
and the port number on which the server is listening. To make a connection request, the client
tries to rendezvous with the server on the server's machine and port. The client also needs to
identify itself to the server so it binds to a local port number that it will use during this
connection. This is usually assigned by the system.
2.2Socket
On the client side, if the connection is accepted, a socket is successfully created and the client
can use the socket to communicate with the server.
The client and server can now communicate by writing to or reading from their sockets.
The java.net package in the Java platform provides a class, Socket, that implements one side of a
two-way connection between our Java program and another program on the network. The Socket
class sits on top of a platform-dependent implementation, hiding the details of any particular
9
system from our Java program. By using the java.net.Socket class instead of relying on native
code, our Java programs can communicate over the network in a platform-independent fashion.
Additionally, java.net includes the ServerSocket class, which implements a socket that servers
can use to listen for and accept connections to clients.
Object Serialization is a mechanism used to read or write an entire object from a file along with
the type of data it holds. A serialized object represented as a sequence of bytes includes the
object’s data as well as information about the object’s type and the types of data stored in the
object. Hence we would be able to know if we are inputting an int, a double or strings. After a
serialized object is written into a file, it can be read from the file and deserialized, i.e. the type
information and bytes that represent the object and its data can be used to recreate the object in
memory.
3. METHODOLOGY
The overall working of Remote Desktop application has following three functional components
i. The GUI
ii. The Server
iii. The Client
3.1.1 Overview
GUI acts as an interface to allow various administrative works on the remote server and client.
GUI performs following task
It opens the graphical interface for the program.
It allows hosting of a connection on a server.
It is used to accept and disconnect clients.
It displays the login form for client in which username and password is used for
authentication.
It allows to choose the image quality i.e. the compression level of the image. For
example, for a LAN connection compression may not be necessary as the bandwidth is
high but for a connection over the internet, image size is more of a concern over image
quality.
It displays the connection log that consists of IP and port address.
It displays the connection and processing logs.
It creates new user for client.
11
3.2.1 Overview
Server is a program that runs on the PC which has to be remotely accessed. It establishes the
connection with different clients and receives and executes the command sent by the client.
Basic functions performed by the Server are listed below
It is secured with passwords.
It handles the commands from client.
It authorizes the client and gives access to them.
It can handle multiple clients simultaneously.
3.2.2 Design
The overall design of server can be divided into four functional components.
i. Connection module
ii. Screen record module
iii. Receive command module
Connection module
It handles the connection between the server and client. It remains in continuous looping state
while waiting for the connection request from client and establish the connection after receiving
the request. It performs authentication for server as well as clients. It provides flexibility with
various operations. Basically it provides the security to the Remote Desktop Application.
For the connection between server and client, socket is used.
Basic Implementation of Connection using socket is listed below.
Initialize socket on Remote PC using IP and port number
Server’s WAN IP must be known by the client.
It receives request from client.
Connection uses TCP/IP connection i.e. no data loss.
12
1>ServerInitiate class
It is responsible for authentication and connection of server. It displays the IP of the host
computer and gets the port number from user. Using these values, it sets up a ServerSocket and
waits for a connection. When a client connects, it initiates the ScreenRecorder and
ReceiveCommands classes.
2>ScreenRecorder Class
It receives a screenshot from the GetImage class. The compare class determines which parts of
image have changed. It then passes these parts to the ImageKit class which compresses the image
using the desired compression level from the user and returns a bytearray of the compressed
image. This bytearray is sent to the client via the ObjectOutputStream.
3>ReceiveCommands Class
This class receives commands from the client as integer values and executes it.
14
GetValues Class
It consists of methods that return required data such as the screen dimensions and coordinates to
center the viewing window.
GetImage Class
It uses the robot class to capture the screen using the dimensions from the GetValues class.
ImageKit Class
It performs image compression by first converting the bufferedImage into a bytearray and then
using the ImageIO class to compress. This class is also used in the client side to get an image
from a byteArray.
Compare Class
As the name suggests, this class compares two images for any changes. It returns an array of 16
boolean variables each representing if each part of image has changed.
Clipboardkit
It is used to access the system clipboard to get and set text to the clipboard.
Settings
It is a class used to store data to send to the client from server and vice versa.
Split
3.2.4 Implementation
For the implementation of the remote server, after the GUI appears we need to assign the
username and password for authentication, quality for image compression, server’s IP and port
for connection and then click the ‘Host’ button for hosting server.
While running, the program does the following jobs.
15
Initializes server socket by using IP of the host computer and port number entered by the
user and waits for a client to connect.
Accepts the connection.
Sends the screenshot of the server’s desktop and sends to the client.
Receives the commands from the client and executes it.
Sends the new screen shot, after the action is performed, to the client. The new screenshot
is sent after the comparison with the previous screenshot.
3.3.1 Overview
The client module is used to access the computer in which the server module is running. Client
searches for the server and connects to it using server’s IP and port.
The basic functions of client are
It tries to connect to the server using the IP and port address the user provides.
It accesses the server with valid username and password.
It runs independently even if there are other clients connected to same server.
Once it is connected with server it sends commands that specifies actions for server to
perform
3.3.2 Design
1>ClientInitiate
Gets the IP of server and port no from the user and creates a connection with the server. When
connected, it calls the receiver.
2>ScreenReciever
Receives image parts at certain intervals, joins the parts and displays them in a ScrollPane.
3> ScrollPane
Display image.
5>SendCommands Class
It detects mouse and keyboard events in its window and sends integers representing these events
to the server.
6>Utility classes
3.3.4 Implementation
For the implementation of the client, after the GUI appears we need to type the username and
password for authentication, quality for image compression, server’s IP and port for connection
and then click the ‘Connect’ button.
While running, the program does the following jobs.
Creates connection with server after entering server’s port and IP address
After the connection a new frame appears showing current server screen.
Sends commands to the server for actions to perform. For eg: When we move the mouse
over the frame, this results in moving the mouse at the server side. The same happens
when we right/left click mouse button or type a key while the frame is in focus. In this
way, remote client can perform any desired action like opening applications on server’s
side like on its own desktop. The server response to client action is immediate.
19
4.1 Theory
A raster is a rectangular area of pixels from an image or a piece of an image. Java rasters are
representated by the java.awt.image.Raster class and its subclasses. We can create a raster using
these classes or obtain one from an Image object, BufferedImage object or from an array of
pixels. To store information about the pixels of a raster you use data buffers that represent
instances of the direct DataBuffers subclasses. The SampleModel class and its subclasses
manage the rules for extracting and storing pixels into the data buffers. These classes contain
enough methods for providing to the programmer a large flexibility in working with rasters. So,
A Raster encapsulates a DataBuffer that stores the sample values and a SampleModel that
describes how to locate a given sample value in a DataBuffer.
The abstract class SampleModel contains methods for extracting a pixel's samples, for storing
them in data buffers, and for extracting them from data buffers. To store the samples in
DataBuffers, we use arrays of primitive data types. In fact, a DataBuffer object encapsulates one
or more arrays of primitive data types. Generally, each array in the data buffer is in fact, a block
of data that has a specified dimension. The first block is known as block 0, the second is block 1,
etc.
20
In our project, we are using the instance of the “ java.awt.image.DataBufferInt ” where the data
is represented in the int primitive type. So the properties of each pixel is stored as an integer
value in the databuffer.
1. The first way to store samples is where each sample is stored as a separate element in the
databuffer. So we would have a different entry for each A, R, G, B components of each
pixel. If all samples are stored in one single block or buffer it is called the
PixelInterLeavedSampleModel and if we have different blocks for different components
it is called the BandedSampleModel.
2. The second way to store the samples is where is all the samples of one or more pixels is
stored a databuffer element. If a single pixel is represented by one databuffer element it is
called the SinglePixelPackedSampleModel and if more than one pixel is represented in
one element, it is called the MultiPixelPackedSampleModel.
Remember that DataBuffer's blocks are counting from 0 to n-1. The samples stored into a
DataBuffer are also counting from 0 to n-1.
21
4.2 Methodology
For Image Comparison is our project, the image is first divided into a grid with four rows and
four columns so each screenshot is divided into 16 parts as shown in the figure below:
Then the dimensions for each part is given by ScreenWidth/4 and ScreenHeight/4.
The compare class determines which parts of the image has changed so only those parts can be
sent to the remote computer as the other parts are the same.
An Array of 16 Boolean variables is constructed where each variable represents one part of the
screen and it takes the value true if that part is the same and false if that part has changed.
To determine if the image part has changed, we proceed in the following manner:
22
1. First, the Raster is obtained from the BufferedImage that holds the most recent screenshot
and also the previous screenshot.
2. From the Raster, we obtain the databuffer of the image which is of type DataBufferInt
and SampleModel is SinglePixelPackedSampleModel so each pixel is now represented
by a single integer value that is stored sequentially in an array. So the elements in the
databuffer array represent the following pixels:
Databuffer[0] = Pixel(0,0)
Databuffer[1] = Pixel(1,0)
Databuffer[2] = Pixel(2,0)
……………………………………..
Databuffer[Width*Height] = Pixel(Width,Height)
3. The number of pixels for each part is assigned to variable size given by:
Size = (Width/4)*(Height/4)
4. For each Image Part, the integer values representing each pixel in that part of image is
compared to the corresponding pixel of the previous image. The total number of similar
pixels in each part is calculated and stored in variable same.
5. If there is a change of 0.01% in the image part then that part is considered to have
changed and the flag representing that image is set to false. The 0.01% margin is
considered because two screenshots of the same desktop condition may result in a
difference in the A,R,G,B values in any pixel due to different factors. The difference
however minute it may be will result in a difference in the integer representation of the
pixel. So two screenshots even if they are similar will be considered different due to this
type of variation in only a single pixel.
23
6. After it is determined which parts of the images have changed, these values are returned
to the main program which can then only send the changed images.
5. IMAGE COMPRESSION
After it has been determined which parts of the screenshot is to be sent, the parts are then
compressed before transfer to the remote computer.
5.1 Theory
Compression in our program is done using the JPEG compression method. The JPEG standard
specifies the codec, which defines how an image is compressed into a stream of bytes and
decompressed back into an image, but not the file format used to contain that stream.
The degree of compression can be adjusted, allowing a selectable tradeoff between storage size
and image quality. JPEG typically achieves 10:1 compression with little perceptible loss in
image quality. JPEG compression is used in a number of image file formats. The JPEG
compression algorithm is at its best on photographs and paintings of realistic scenes with smooth
variations of tone and color.
The compression method is usually lossy, meaning that some original image information is lost
and cannot be restored (possibly affecting image quality.) The image accuracy is not as
important as the conserving of bandwidth concerned with our project so this method is preferred.
Also since, JPEG is the most common format for storing and transmitting photographic images
on the World Wide Web, it is ideal for our purpose for connections over the internet.
5.2 Methodology
In Java, JPEG compression can be performed on an image by using the javax.imageio package
which include the ImageIO, ImageWriter, ImageWriteParam, IIOImage & the
ImageOutputStream classes.
1. First, we use the ImageIO class to obtain an ImageWriter object that may be used to
perform the write.
Iterator writers = ImageIO.getImageWritersByFormatName("jpg");
ImageWriter writer = (ImageWriter)writers.next();
Writers may be retrieved based on file contents, file suffix, or MIME type. We use JPEG
compression so we obtain writers based on file format jpg.
2. Once a writer has been obtained, it must be supplied with an output source. Writers are able
to write to an ImageOutputStream, which is a special output source that is defined by the
Image I/O API. Obtaining an ImageOutputStream is straightforward. Given an output
source in the form of a OuputStream, an ImageOutputStream is produced by the call:
ImageOutputStream ios = ImageIO.createImageOutputStream(outputStream);
3. Once a destination stream has been obtained, it is attached to the writer by calling
writer.setOutput(ios);
This sets the outputstream for the writer to write to.
4. The write method with an additional parameter of type ImageWriteParam. An
ImageWriteParam allows a region of interest to be specified along with factors that may be
used to obtain a scaled-down version of the image.
First the default parameter is obtained by:
ImageWriteParam param = writer.getDefaultWriteParam();
We can then set the level of compression for this parameter which is in the range from 0
to 1 where 1 specifies zero level of compression and 0 specifies maximum compression.
This is done by:
param.setCompressionQuality(quality);
5. Data is then written to the output stream with the previously set parameters as a sequence
of bytes which is done by:
writer.write(null, new IIOImage(image, null, null), param);
A new IIOImage needs to be created as it is the parameter required by the method.
In the receiver side, this stream of bytes is read by using ImageIO.read() function which reads
the stream of bytes to form a BufferedImage which can then be displayed.
25
6. APPLICATIONS
Remote Desktop can also be commonly used on desktop with Linux installations to connect to
Microsoft Windows computers running Terminal Services. Since RDJ is coded in Java it
provides platform independent remote assistance.
In enterprise installations, system administrators typically have to deal with a large number of
pretty basic problems on users' machines. Remotely taking control of a users’ desktop to fix the
problem while at the same time training the user to resolve the problem is an effective and
simple way to handle such types of support scenarios. So, this project is very useful for
maintenance.
This application can also be used for educational purpose, like virtual classroom, where remote
viewing will preferentially assist.
26
7. LIMITATIONS
As everything has pros and cons. Remote desktop Java has its limitations too. The main
limitations are:
The same remote desktop view is visible for multiple clients at once, so there can be conflict
with mouse movements and keyboard strokes performed by various clients simultaneously.
For presentation purpose, we want one participant to take a control on PC and manipulate
with mouse and keyboard, while other watch the process in a view mode without having
control of mouse and keyboard stokes.
IP address and port address of hosting remote server is to be known initially by the client.
Full-screen mode for client side for the viewing of remote desktop is not implemented.
27
8. FUTURE ENHANCEMENTS
Even though it is fully working application, we can augment some features to it in the future to
enhance its functionalities.
Any unauthorized user can access the remote desktop if he knows the host ip address and
port address. So, data security is vulnerable, which we intend to eliminate by applying
strong encryption algorithms so that unauthenticated intruders can’t get access to the
hosting remote server.
IP address and port address of host can be placed on the web server with only
authenticated clients having access to it, so that client can connect to remote desktop
easily and doesn’t need to know the ip address and port address initially.
Audio can be recorded and transmitted along with the images which can be useful for
remote presentation in classes.
We can provide features like capturing a remote desktop screen and record remote
activity as an AVI file.
28
9. RESULT
9.1 Screenshot 1
29
9.2 ScreenShot 2
10. CONCLUSION
Despite some difficulties and short time duration for completion of project, we managed to
complete the project, Remote Desktop Java, proposed to the Department of Electronics and
Computer Engineering, as the third year minor project within scheduled time. During project
development, we became familiar with various tools of software development.
All the objectives during proposal submission and midterm report have been met. As this project
is done completely in Java, it enhanced our skills in this language. By the end of this project, we
have been able to provide a software with interactive GUI interface, that allows client to control
remote server in various ways. Multicasting feature is also available, which enables multiple
clients to connect to single remote server simultaneously.
The limitations faced during this time will be removed and future enhancement will be done as
part of maintaining and upgrading our software.
30
REFERENCES