You are on page 1of 54

Virtual Controller

Abstract
Virtual Controller: This program allows any computer to control other PCs remotely. Project aims at administering a remote computer using network communication. The remote computer acts as client and the controlling computer acts as a server. Any number of clients can be connected to the server. The core function of client is sending a screen shot of the clients desktop at a predefined amount of time. For each client a new frame is generated and the screen shot is displayed at the sever side. The clients control is communicated in the form of mouse movement and key strokes. Program Features:

View remote desktop Mouse movement control Mouse buttons control Keyboard control

Modules: Develop Remote Server Develop Remote Client

[1] SRTIST(I.T Dept)

Virtual Controller

1. INTRODUCTION
1.1 Purpose
Administration in computer organization is a modern professional responsible for the maintenance of computer hardware and software that comprises a computer network. This normally includes the deployment, configuration, maintenance and monitoring of active Employee function. A related role is that of the network specialist, or network analyst, who concentrates on network design and security. Network administrators are responsible for making sure computer hardware and the network infrastructure itself is maintained properly for an IT organization. They are deeply involved in the rolling out new software installs, and as well as employee tasks what actually they are doing in the time of job. But there is a problem to maintain all networks with one administrator. So our virtual controller program allows any computer to control other PCs remotely. Project aims at administering a remote computer using network communication. The remote computer acts as client and the controlling computer acts as a server. Any number of clients can be connected to the server. The core function of client is sending a screen shot of the clients desktop at a predefined amount of time. For each client a new frame is generated and the screen shot is displayed at the sever side. The clients control is communicated in the form of mouse movement and key strokes.

1.2 Scope
Virtual Controller provides some very useful and general important functions for the administrator to maintain the clients function or tasks in computer network and, in this application, reduce the burden on administrator work and saving the time for all levels of network. This the client side, its core function is sending a screen shot of the client's desktop every predefined amount of time. Also it receives server commands such as "move the mouse command", and then executes the command at the client's PC. Any [2] SRTIST(I.T Dept)

Virtual Controller
number of clients can be connected to the server. The core function of client is sending a screen shot of the clients desktop at a predefined amount of time.

1.3 Project Overview


Although virtual Controller is an innovative application, the modern formulation of it is often given in terms of the existing system problems, in generally administrators are responsible for making sure computer hardware and the network infrastructure itself is maintained properly for an IT organization. They are deeply involved in the rolling out new software installs, and as well as employee tasks what actually they are doing in the time of job. But there is a problem to maintain all networks with one administrator. This is the administrator waits for clients connections and per each connected client, a new frame appears showing the current client screen. When you move the mouse over the frame, this results in moving the mouse at the client side. The same happens when you right/left click mouse button or type a key while the frame is in focus.

1.4 Problem Definition 1.4.1 Existing System


Administrators are responsible for making sure rolling out new software installs, and as well as employee tasks what actually they are doing in the time of job. But there is a problem to maintain all networks with one administrator. If admin want to know the details and the clients tasks he should do manually see and take the information from the clients or using the Ip address he can connect the system but there is problem will occurs in the client said like system hanging and etc .

1.4.2 Proposed System


This program allows any computer to control other PCs remotely. Project aims at administering a remote computer using network communication. The remote computer acts as client and the controlling computer acts as a server. Any number of clients can be connected to the server. The modern virtual controller achieves in terms of the existing system problems, in generally administrators are server part which waits for clients [3] SRTIST(I.T Dept)

Virtual Controller
connections and per each connected client, a new frame appears showing the current client screen. When you move the mouse over the frame, this results in moving the mouse at the client side. The same happens when you right/left click mouse button or type a key while the frame is in focus. Client side, its core function is sending a screen shot of the client's desktop every predefined amount of time. Also it receives server commands such as "move the mouse command", and then executes the command at the client's PC.

1.4.3 Program Features


View remote desktop Mouse movement control Mouse buttons control Keyboard control

[4] SRTIST(I.T Dept)

Virtual Controller

2. MODULE DESCRIPTION
3.1 Modules:
Develop Remote Server Develop Remote Client.

3.1.1. Remote Server This is the server part which waits for clients connections and per each connected client, a new frame appears showing the current client screen. When you move the mouse over the frame, this results in moving the mouse at the client side. The same happens when you right/left click mouse button or type a key while the frame is in focus.

3.1.2. Remote Client This the client side, its core function is sending a screen shot of the client's desktop every predefined amount of time. Also it receives server commands such as "move the mouse command", and then executes the command at the client's PC.

[5] SRTIST(I.T Dept)

Virtual Controller

3. PROJECT REQUIREMENTS AND SPECIFICATIONS


3.1 Operating Environment
Software Requirements are Windows as Operating System, Linux or Mac operating system, Java 2 standard edition, Java swings. Hardware Requirements are P2 above processor, 128MB+ of main memory (RAM) and 100MB hard disk and data base memory with LAN connection or internet connection.

3.2 Implementation Constraints


This project will be developed using the technologies like Java 2 standard edition, Java swings. Also well be learning clearly about Software Development Life Cycle.

3.3 Hardware Requirements


Processor:: Pentium-III (or) Higher Ram:: 64MB (or) Higher Cache:: 512MB Hard disk:: 40GB

3.4 Software Requirements


Tools:: MicroSoft Front Operating System:: Windows.NET/2000/XP Client Side:: GUI Technologies:: Java, java net and Swings

[6] SRTIST(I.T Dept)

Virtual Controller

4. FEASIBILITY STUDY
4.1 Feasibility Study:
The next step in analysis is to verify the feasibility of the proposed system. All projects are feasible given unlimited resources and infinite time. But in reality both resources and time are scarce. Project should confirm to time bounce and should be optimal in there consumption of resources. The development of computer-based system is likely to be played by Scarcity of resources and difficulty in completion dates. Feasibility study is the measure of how beneficial or practical information system will be to an organization. Further developer would like to finalize the software and hardware requirements to develop the proposed system. The objective of Feasibility Study is to evaluate the relevant factors involved in the problem statement, considers preliminary alternative solutions weakness and advantages, and recommended a feasible solution to the problem statement. A feasibility study is an evaluation of a proposal designed to determine the difficulty in carrying out a designated task. Generally, a feasibility study precedes technical development and project implementation. The most important phase in a project development is judging whether the project will be feasible or not. A project developed which is not feasible will serve no purpose. Feasibility has applied to virtual controller pertains to the following areas: Technical feasibility Operational feasibility Economical feasibility

4.1.1 Technical Feasibility [7] SRTIST(I.T Dept)

Virtual Controller
As we are developing this virtual controller Application on Java 2 platform edition which is an open source and free of cost. Once we started developing this application in Java 2 platform edition then they is no need of purchasing any special software or application software for support. Java it self provides all necessary functionalities and resources for developing virtual controller Application. For Example like developing GUI can be developed by AWT or Swing Framework which is much available in Java.

4.1.2 Operational Feasibility To determine the operational feasibility of the system we should take into consideration the awareness level of the users. Users who are using this virtual controller Application dont require much knowledge of how to use. Just Users should have basic concept of what is virtual controller? Every thing will be understood by user once he sees the application. 4.1.3 Economic Feasibility To decide whether a project is economically feasible, or not we have to consider various factors as: Cost benefit analysis Long-term returns Maintenance costs

[8] SRTIST(I.T Dept)

Virtual Controller

5. DESIGN OBJECTIVES
Design is the first step in moving from problem domain to the solution domain. Design is essentially the bridge between requirements specification and the final solution. The goal of design process is to produce a model or representation of a system, which can be used later to build that system. The produced model is called the Design of the System. It is a plan for a solution for the system.

5.1 Unified Modeling language


Unified modeling language is a popular language that has been using for modeling the object oriented software. It is a language for visualizing, specifying, constructing and documentation of software artifacts. Object Management Group (OMG) has first adopted in 1997 as a language for Object-Oriented Analysis and Design. It uses graphical notations to articulate the software design projects. UML is a very significant part of development processes. (Grady Booch & Jim Rumbaing, 1994) These are the artifacts of a software-intensive system. A Conceptual Model Of Uml: The three major elements of UML are The UMLs basic building blocks The rules that dictate how those building blocks may be put together. Some common mechanisms that apply throughout the UML. Relationship In The Uml: There are four kinds of relationships in the UML: 1. Dependency 2. Association 3. Generalization 4. Realization [9] SRTIST(I.T Dept)

Virtual Controller

5.1.1 Goals of UML: 1. It offers the users to express visual modeling language and ready to use. 2. To extend the core concepts, various extensibility and specialization mechanisms are provided. 3. Development processes and programming language which are in particular are made to be independent by the UML design. 4. Necessary understanding of the language is provided formally. 5. Development concepts like components, frameworks, collaborations and patterns. 6. The market of the Object-Oriented tools growth must be encouraged.

5.1.2 UML DIAGRAMS: Class Diagram: Class diagrams are widely used to describe the types of objects in a system and their relationships. Class diagrams model class structure and contents using design elements such as classes, packages and objects. Class diagrams describe three different perspectives when designing a system, conceptual, specification, and implementation. These perspectives become evident as the diagram is created and help solidify the design. Class diagram tell about the list of classes with their attributes and methods which are used in each and every module. Use Case Diagram: Here user is the main heart of our application and we are providing so many options to maintain administration functions, for the need to add port number and ip address for the seeing client system, similarly client also give the port number and ip address .but client

[10] SRTIST(I.T Dept)

Virtual Controller
does not connect the server just giving information to the server. If the ip addresses are validate then only streaming will continue. Interaction Diagram An Interaction diagram shows an interaction, consisting of a set of objects and their relationships, including the messages that may be dispatched among them. Interaction diagrams are used for modeling the dynamic aspects of the system. A sequence diagram is an interaction diagram that emphasizes the time ordering of the messages. Graphically, a sequence diagram is a table that shows objects arranged alongs the X-axis and messages, ordered in increasing time, along the Y-axis and messages, ordered in increasing time, along the Y-axis.

Sequence Diagram:
Sequence diagrams demonstrates the sequential flow of software architecture used in this application .Sequence diagrams document the interactions between classes to achieve a result, such as a use case. Because UML is designed for object oriented programming, this communications between classes are known as messages. The sequence diagrams lists diagrams lists objects horizontally, and time vertically, and models these messages over time. Activity Diagram An Activity Diagram is essentially a flow chart showing flow of control from activity to activity. They are used to model the dynamic aspects of as system .They can also be used to model the flow of an object as it moves from state to state at different points in the flow of control. An activity is an ongoing non-atomic execution with in a state machine. Activities ultimately result in some action, which is made up of executable atomic computations that result in a change of state of distinguishes a use case diagram from all other kinds of diagrams is its particular content. [11] SRTIST(I.T Dept)

Virtual Controller
State Chart Diagram A state chart diagram shows a state machine .State chart diagrams are used to model the dynamic aspects of the system. For the most part this involves modeling the behavior of the reactive objects. A reactive object is one whose behavior is best characterized by its response to events dispatched from outside its context. A reactive object has a clear lifeline whose current behavior is affected by its past. Class Diagram:

[12] SRTIST(I.T Dept)

Virtual Controller

Use Case Diagram:


[13] SRTIST(I.T Dept)

Virtual Controller

[14] SRTIST(I.T Dept)

Virtual Controller
Sequence Diagram for Server:

Sequence Diagram for Client: [15] SRTIST(I.T Dept)

Virtual Controller

Collaboration Diagram: [16] SRTIST(I.T Dept)

Virtual Controller

Activity Diagram: [17] SRTIST(I.T Dept)

Virtual Controller

State Diagram: [18] SRTIST(I.T Dept)

Virtual Controller

Component diagram:
[19] SRTIST(I.T Dept)

Virtual Controller

Deployment diagram:
[20] SRTIST(I.T Dept)

Virtual Controller

[21] SRTIST(I.T Dept)

Virtual Controller

6. OVERVIEW OF SOFTWARE DEVELOPMENT TOOLS


The life-cycle paradigm demands a systematic, sequential approach to software development that begins at the system level and progresses through requirements analysis, design, coding, testing and maintenance. 6.1 Software Development Lifecycle: a) Analysis Phase: The analysis phase consists of two sub phases: planning and requirements definition. During planning the activities that are performed are - understand the customers problem, developing a recommended solution. Requirements definition is concerned with identifying the basic functions of a software component in a hardware/software/people system. b) Design Phase: Design is concerned with identifying software components, specifying relationships among components, maintaining a record of design decisions. Design consists of architectural design and detailed design. i) Architectural Design involves identifying the software components, decoupling and decomposing them in to processing modules and conceptual data structures and specifying the interconnection between the components. ii) Detailed Design is concerned with the details of how to package the processing modules and how to implement the processing algorithms, data structures and interconnection between them.

c) Implementation Phase: The implementation phase of software development involves translation of design specifications source code and debugging, documentation and unit testing of the source code. [22] SRTIST(I.T Dept)

Virtual Controller
d) Testing Phase: It involves two kinds of testing: i) In integration testing the individual program units or programs are integrated and tested. ii) Acceptance Testing involves planning and execution of various types of tests in order to demonstrate that the implemented software satisfies the stated requirements.

6.2 Java & Its Features:


Java was conceived by James Gosling, Patrick Naughton, Chris Warth, Ed Frank and Mike Sheridan at SUN Microsystems corporation in the year 1991.It took 18 months to develop the 1st working version. This language was initially called OAK, but was renamed JAVA in 1995, many more contributed to the design and evolution of the language.

Java Overview
Java is a powerful but lean object-oriented programming language. It has generated a lot of excitement because it makes it possible to program for Internet by creating Applets which are programs that can be embedded in web page. The context of an applet can be an animation with sound, an interactive game or a ticker tape. With constantly updated stock prices, applets can be just little decorations to liven up web page, or they can be serious applications like Word processor or Spreadsheet. But Java is more than a programming language for writing Applets. It is being used more and more for writing standalone applications as well. It is becoming so popular that many people believe it will become standard language for both general purpose and Internet programming. There are many buzzwords associated with Java, but because of its spectacular growth in popularity, a new buzzword has appeared ubiquitous. Indeed, all indications are that it will soon be everywhere.

[23] SRTIST(I.T Dept)

Virtual Controller
Java builds on the strength of C++. It has taken the best features of C++ and discarded the more problematic and error prone parts. To this lean core, it has added garbage collection (automatic memory management), multithreading (the capacity for one program to do more than one thing at a time), security capabilities. This result is that Java is simple, elegant, and powerful and easy-to-use. Java is actually a platform consisting of 3 components: Java Programming Language Java Library of Classes and Interfaces Java Virtual Machine

The following sections will say more about these components. Java is portable: One of the biggest advantages Java offers is that it is portable. An application written in Java will run on all the major platforms. Any computer with a Javabased browser can run the applications or Applets written in the Java-ProgrammingLanguage. A programmer no longer has to write one program to run on a Macintosh, another program to run on a Windows-machine still another to run on a UNIX-machine and so on. In other words, with Java developers write their programs only once. The Virtual Machine is what gives Java is cross platform capabilities. Rather being compiled into machine language, which is different for each OSs and computer architecture, Java code is compiled into Byte codes. With other Languages, the program code is compiled into a language that the computer can understand. The problem is that other computers with different machine instruction set cannot understand that language. Java code on the other hand is compiled into Byte-Code rather than a machine language. This byte codes go to the JVM, which executes them directly or translates them into the language that is understood by the machine running it. In summary, these means that with the JDBC API extending Java, a programmer writing Java code can access all the major RDBMS on any platform that supports the JVM.

[24] SRTIST(I.T Dept)

Virtual Controller
Java is Object Oriented: The Java programming language is OBJECT-ORIENTED, which makes program design focus on what you are dealing with, rather than on how your are going to do something. This makes it more useful for programming in sophisticated projects, because one can break the things into understandable components. A big benefit is that these components can then be reused. Object-Oriented Languages use the paradigm of classes. In
simplest term, a class includes both the data and the functions to operate on data. You can create an instance of a class, also called an object, which will have all the data members and functionality of its class. Because of this, you can think of a class as being like template, with each object being a specific instance of a particular type of class.

The class paradigm allows one to encapsulate data so that specific data values are those using the data cannot see the function implementation. Encapsulation makes it possible to make the changes in code without breaking other programs that use that code. If for example, the implementation of a function is changed, the change is invisible to any programmer who invokes that function, and does not affect his/her program, except hopefully to improve it.Java includes inheritance, or the ability to derive new classes from existing classes. The derived class, is also called as Sub-Class, inherits all the data in the functions of the existing class.

Java Development Environment: To code, edit, debug and test the java programs, one needs to have a java development environment. At the minimum this will consists of a java compiler, interpreter and applet viewer where applets can be tested. Suns java development kit (JDK) latest version is 2.2 can be freely downloaded from the Internet. Java compiler is available on DOS, Win95, WINNT, Solaris and MAC etc.

[25] SRTIST(I.T Dept)

Virtual Controller

7.CODE
7.1 REMOTE SERVER: 7.1.1 Serverinitiator:
package remoteserver; import java.awt.BorderLayout; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JOptionPane; /** * This is the entry class of the server */ public class ServerInitiator { //Main server frame private JFrame frame = new JFrame(); //JDesktopPane represents the main container that will contain all //connected clients' screens private JDesktopPane desktop = new JDesktopPane(); public static void main(String args[]){ String port = JOptionPane.showInputDialog("Please enter listening port"); new ServerInitiator().initialize(Integer.parseInt(port)); } public void initialize(int port){ try { ServerSocket sc = new ServerSocket(port); //Show Server GUI drawGUI(); //Listen to server port and accept clients connections while(true){ Socket client = sc.accept(); System.out.println("New client Connected to the server"); //Per each client create a ClientHandler new ClientHandler(client,desktop); } } catch (IOException ex) { ex.printStackTrace();

[26] SRTIST(I.T Dept)

Virtual Controller
} } /* * Draws the main server GUI */ public void drawGUI(){ frame.add(desktop,BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Show the frame in a maximized state frame.setExtendedState(frame.getExtendedState()|JFrame.MAXIMIZED_BOTH); frame.setVisible(true); } }

[27] SRTIST(I.T Dept)

Virtual Controller 7.1.2 ClientCommandsSender:


package remoteserver; import java.awt.Rectangle; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.io.IOException; import java.io.PrintWriter; import java.net.Socket; import javax.swing.JPanel; class ClientCommandsSender implements KeyListener, MouseMotionListener,MouseListener { private Socket cSocket = null; private JPanel cPanel = null; private PrintWriter writer = null; private Rectangle clientScreenDim = null; ClientCommandsSender(Socket s, JPanel p, Rectangle r) { cSocket = s; cPanel = p; clientScreenDim = r; //Associate event listners to the panel cPanel.addKeyListener(this); cPanel.addMouseListener(this); cPanel.addMouseMotionListener(this); try { //Prepare PrintWriter which will be used to send commands to //the client writer = new PrintWriter(cSocket.getOutputStream()); } catch (IOException ex) { ex.printStackTrace(); } } //Not implemeted yet public void mouseDragged(MouseEvent e) { } public void mouseMoved(MouseEvent e) { double xScale = clientScreenDim.getWidth()/cPanel.getWidth(); System.out.println("xScale: " + xScale); double yScale = clientScreenDim.getHeight()/cPanel.getHeight();

[28] SRTIST(I.T Dept)

Virtual Controller
System.out.println("yScale: " + yScale); System.out.println("Mouse Moved"); writer.println(EnumCommands.MOVE_MOUSE.getAbbrev()); writer.println((int)(e.getX() * xScale)); writer.println((int)(e.getY() * yScale)); writer.flush(); } //this is not implemented public void mouseClicked(MouseEvent e) { } public void mousePressed(MouseEvent e) { System.out.println("Mouse Pressed"); writer.println(EnumCommands.PRESS_MOUSE.getAbbrev()); int button = e.getButton(); int xButton = 16; if (button == 3) { xButton = 4; } writer.println(xButton); writer.flush(); } public void mouseReleased(MouseEvent e) { System.out.println("Mouse Released"); writer.println(EnumCommands.RELEASE_MOUSE.getAbbrev()); int button = e.getButton(); int xButton = 16; if (button == 3) { xButton = 4; } writer.println(xButton); writer.flush(); } //not implemented public void mouseEntered(MouseEvent e) { } //not implemented public void mouseExited(MouseEvent e) { } //not implemented public void keyTyped(KeyEvent e) { }

[29] SRTIST(I.T Dept)

Virtual Controller
public void keyPressed(KeyEvent e) { System.out.println("Key Pressed"); writer.println(EnumCommands.PRESS_KEY.getAbbrev()); writer.println(e.getKeyCode()); writer.flush(); } public void keyReleased(KeyEvent e) { System.out.println("Mouse Released"); writer.println(EnumCommands.RELEASE_KEY.getAbbrev()); writer.println(e.getKeyCode()); writer.flush(); } }

[30] SRTIST(I.T Dept)

Virtual Controller 7.1.3ClientHandler:


package remoteserver; import java.awt.BorderLayout; import java.awt.Rectangle; import java.beans.PropertyVetoException; import java.io.IOException; import java.io.ObjectInputStream; import java.net.Socket; import javax.swing.JDesktopPane; import javax.swing.JInternalFrame; import javax.swing.JPanel; import java.net.InetAddress; class ClientHandler extends Thread { private JDesktopPane desktop = null; private Socket cSocket = null; private JInternalFrame interFrame = new JInternalFrame("Client Screen", true, true, true); private JPanel cPanel = new JPanel(); public ClientHandler(Socket cSocket, JDesktopPane desktop) { this.cSocket = cSocket; this.desktop = desktop; start(); } /* * Draw GUI per each connected client */ public void drawGUI(){ interFrame.setLayout(new BorderLayout()); interFrame.getContentPane().add(cPanel,BorderLayout.CENTER); interFrame.setSize(100,100); desktop.add(interFrame); try { //Initially show the internal frame maximized interFrame.setMaximum(true); } catch (PropertyVetoException ex) { ex.printStackTrace(); } //this allows to handle KeyListener events cPanel.setFocusable(true); interFrame.setVisible(true); }

[31] SRTIST(I.T Dept)

Virtual Controller

public void run(){ //used to represent client screen size Rectangle clientScreenDim = null; //Used to read screenshots and client screen dimension ObjectInputStream ois = null; //start drawing GUI drawGUI(); try{ //Read client screen dimension ois = new ObjectInputStream(cSocket.getInputStream()); clientScreenDim =(Rectangle) ois.readObject(); }catch(IOException ex){ ex.printStackTrace(); }catch(ClassNotFoundException ex){ ex.printStackTrace(); } //Start recieveing screenshots new ClientScreenReciever(ois,cPanel); //Start sending events to the client new ClientCommandsSender(cSocket,cPanel,clientScreenDim); } }

[32] SRTIST(I.T Dept)

Virtual Controller 7.1.4ClientScreenReciever:


package remoteserver; import java.awt.Graphics; import java.awt.Image; import java.io.IOException; import java.io.ObjectInputStream; import javax.swing.ImageIcon; import javax.swing.JPanel; /** * ClientScreenReciever is responsible for recieving client screenshot and displaying * it in the server. Each connected client has a separate object of this class */ class ClientScreenReciever extends Thread { private ObjectInputStream cObjectInputStream = null; private JPanel cPanel = null; private boolean continueLoop = true; public ClientScreenReciever(ObjectInputStream ois, JPanel p) { cObjectInputStream = ois; cPanel = p; //start the thread and thus call the run method start(); } public void run(){ try { //Read screenshots of the client then draw them while(continueLoop){ //Recieve client screenshot and resize it to the current panel size ImageIcon imageIcon = (ImageIcon) cObjectInputStream.readObject(); System.out.println("New image recieved"); Image image = imageIcon.getImage(); image = image.getScaledInstance(cPanel.getWidth(),cPanel.getHeight() ,Image.SCALE_FAST); //Draw the recieved screenshot Graphics graphics = cPanel.getGraphics(); graphics.drawImage(image, 0, 0, cPanel.getWidth(),cPanel.getHeight(),cPanel); } } catch (IOException ex) { ex.printStackTrace(); } catch(ClassNotFoundException ex){ ex.printStackTrace(); } }}

[33] SRTIST(I.T Dept)

Virtual Controller 7.2 REMOTE CLIENT: 7.2.1 ClientInitiator:


package remoteclient; import java.awt.AWTException; import java.awt.Dimension; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Rectangle; import java.awt.Robot; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.net.Socket; import java.net.UnknownHostException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; /** * * This class is responsible for connecting to the server * and starting ScreenSpyer and ServerDelegate classes */ public class ClientInitiator { Socket socket = null; public static void main(String[] args){ String ip = JOptionPane.showInputDialog("Please enter server IP"); String port = JOptionPane.showInputDialog("Please enter server port"); new ClientInitiator().initialize(ip, Integer.parseInt(port)); } public void initialize(String ip, int port ){ Robot robot = null; //Used to capture the screen Rectangle rectangle = null; //Used to represent screen dimensions try { System.out.println("Connecting to server .........."); socket = new Socket(ip, port); System.out.println("Connection Established."); //Get default screen device GraphicsEnvironment gEnv=GraphicsEnvironment.getLocalGraphicsEnvironment();

[34] SRTIST(I.T Dept)

Virtual Controller
GraphicsDevice gDev=gEnv.getDefaultScreenDevice(); //Get screen dimensions Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); rectangle = new Rectangle(dim); //Prepare Robot object robot = new Robot(gDev); //draw client gui drawGUI(); //ScreenSpyer sends screenshots of the client screen new ScreenSpyer(socket,robot,rectangle); //ServerDelegate recieves server commands and execute them new ServerDelegate(socket,robot); } catch (UnknownHostException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } catch (AWTException ex) { ex.printStackTrace(); } } private void drawGUI() { JFrame frame = new JFrame("Remote Admin"); JButton button= new JButton("Terminate"); frame.setBounds(100,100,150,150); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(button); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } } ); frame.setVisible(false); } }

[35] SRTIST(I.T Dept)

Virtual Controller 7.2.2ScreenSpyer:


package remoteclient; import java.awt.Rectangle; import java.awt.Robot; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.ObjectOutputStream; import java.net.Socket; import javax.swing.ImageIcon; /** * This class is responisble for sending sreenshot every predefined duration */ class ScreenSpyer extends Thread { Socket socket = null; Robot robot = null; // Used to capture screen Rectangle rectangle = null; //Used to represent screen dimensions boolean continueLoop = true; //Used to exit the program public ScreenSpyer(Socket socket, Robot robot,Rectangle rect) { this.socket = socket; this.robot = robot; rectangle = rect; start(); } public void run(){ ObjectOutputStream oos = null; //Used to write an object to the streem try{ //Prepare ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream()); /* * Send screen size to the server in order to calculate correct mouse * location on the server's panel */ oos.writeObject(rectangle); }catch(IOException ex){ ex.printStackTrace(); } while(continueLoop){ //Capture screen BufferedImage image = robot.createScreenCapture(rectangle); /* I have to wrap BufferedImage with ImageIcon because BufferedImage class

[36] SRTIST(I.T Dept)

Virtual Controller
* does not implement Serializable interface */ ImageIcon imageIcon = new ImageIcon(image); //Send captured screen to the server try { System.out.println("before sending image"); oos.writeObject(imageIcon); oos.reset(); //Clear ObjectOutputStream cache System.out.println("New screenshot sent"); } catch (IOException ex) { ex.printStackTrace(); } //wait for 100ms to reduce network traffic try{ Thread.sleep(100); }catch(InterruptedException e){ e.printStackTrace(); } } } }

[37] SRTIST(I.T Dept)

Virtual Controller 7.2.3ServerDelegate:


package remoteclient; import java.awt.Robot; import java.io.IOException; import java.net.Socket; import java.util.Scanner; /* * Used to recieve server commands then execute them at the client side */ class ServerDelegate extends Thread { Socket socket = null; Robot robot = null; boolean continueLoop = true; public ServerDelegate(Socket socket, Robot robot) { this.socket = socket; this.robot = robot; start(); //Start the thread and hence calling run method } public void run(){ Scanner scanner = null; try { //prepare Scanner object System.out.println("Preparing InputStream"); scanner = new Scanner(socket.getInputStream()); while(continueLoop){ //recieve commands and respond accordingly System.out.println("Waiting for command"); int command = scanner.nextInt(); System.out.println("New command: " + command); switch(command){ case -1: robot.mousePress(scanner.nextInt()); break; case -2: robot.mouseRelease(scanner.nextInt()); break; case -3: robot.keyPress(scanner.nextInt()); break; case -4: robot.keyRelease(scanner.nextInt()); break;

[38] SRTIST(I.T Dept)

Virtual Controller
case -5: robot.mouseMove(scanner.nextInt(), scanner.nextInt()); break; } } } catch (IOException ex) { ex.printStackTrace(); } } }

[39] SRTIST(I.T Dept)

Virtual Controller

8.TESTING
7.1 Software Testing
Software testing is a critical element of software quality assurance and represents the ultimate review of specification, design and code generation.

7.1.1 Testing Objectives


To ensure that during operation the system will perform as per specification. To make sure that system meets the user requirements during operation. To make sure that during the operation, incorrect input, processing and output will be detected. To see that when correct inputs are fed to the system the outputs are correct. To verify that the controls incorporated in the same system as intended.

Testing is a process of executing a program with the intent of finding an error. A good test case is one that has a high probability of finding an as yet undiscovered error The software developed has been tested successfully using the following testing strategies and any errors that are encountered are corrected and again the part of the program or the procedure or function is put to testing until all the errors are removed. A successful test is one that uncovers undiscovered error. Note that the result of the system testing will prove that the system is working correctly. It will give confidence to system designer, users of the system and prevent frustration during implementation process etc.

[40] SRTIST(I.T Dept)

Virtual Controller

7.2TEST CASE DESIGN White Box Testing


White box testing is a testing case design method that uses the control structure of the procedure design to derive test cases. All independent path in a module are exercised at least once, all logical decisions are exercised at once, execute all loops at boundaries and within their operational bounds exercise internal data structure to ensure their validity. Here the customer is given three chances to enter a valid choice out of the given menu. After which the control exits the current menu.

Black box Testing


Black Box Testing attempts to find errors in following areas or categories, incorrect or missing functions, interface error, errors in data structures, performance error and initialization and termination error. Here all the input data must match the data type to become a valid entry. The following are the different tests at various levels: Unit Testing Unit testing is essentially for the verification of the code produced during the coding phase and the goal is to test the internal logic of the module/program. In the Generic code project, the unit testing is done during coding phase of data entry forms whether the functions are working properly or not. In this phase all the drivers are tested they are rightly connected or not. Integration Testing All the tested modules are combined into sub systems, which are then tested. The goal is to see if the modules are properly integrated, and the emphasis being on [41] SRTIST(I.T Dept)

Virtual Controller
the testing interfaces between the modules. In the generic code integration testing is done mainly on table creation module and insertion module. Validation Testing This testing concentrates on confirming that the software is error-free in all respects. All the specified validations are verified and the software is subjected to hardcore testing. It also aims at determining the degree of deviation that exists in the software designed from the specification; they are listed out and are corrected. System Testing This testing is a series of different tests whose primary computer-based system. This involves: Implementing the system in a simulated production environment and testing it. Introducing errors and testing for error handling. goal is to exercise the

7.3 Test Cases


The test cases that are used in the project are: TEST CASE 1: Same port number should be entered at both client and server end. Otherwise it displays Connection Failed error message.

TEST CASE 2: The IP address of server should be entered correctly at the clients end. Otherwise error message is displayed.

[42] SRTIST(I.T Dept)

Virtual Controller

8. INPUT & OUTPUT SCREENSHOTS


In this initially user selects the java programming file and those should be in the form of either class files or source files. After that he add the source file and class file and also set some important setting then select go for processing controller application.

Screen 1:

[43] SRTIST(I.T Dept)

Virtual Controller Screen 2:

[44] SRTIST(I.T Dept)

Virtual Controller Screen 3:

[45] SRTIST(I.T Dept)

Virtual Controller

[46] SRTIST(I.T Dept)

Virtual Controller Screen 4:

[47] SRTIST(I.T Dept)

Virtual Controller

9. REQUIRED PACKAGES
import java.awt.AWTException; import java.awt.Dimension; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Rectangle; import java.awt.Robot; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.net.Socket; import java.net.UnknownHostException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane;

When user run server application it should ask listening port number:
String port = JOptionPane.showInputDialog("Please enter listening port"); new ServerInitiator().initialize(Integer.parseInt(port)); . . . public void initialize(int port){ [48] SRTIST(I.T Dept)

Virtual Controller
try { ServerSocket sc = new ServerSocket(port); //Show Server GUI drawGUI(); //Listen to server port and accept clients connections while(true){ Socket client = sc.accept(); System.out.println("New client Connected to the server"); //Per each client create a ClientHandler new ClientHandler(client,desktop); } } catch (IOException ex) { ex.printStackTrace(); } }

Server Started Successfully:


public ClientHandler(Socket cSocket, JDesktopPane desktop) { this.cSocket = cSocket; clientName=cSocket.getInetAddress().toString(); System.out.println("new Client is"+clientName); interFrame= new JInternalFrame(clientName, true, true, true); this.desktop = desktop; start(); } /* * Draw GUI per each connected client */ [49] SRTIST(I.T Dept)

Virtual Controller
public void drawGUI(){ interFrame.setLayout(new BorderLayout()); interFrame.getContentPane().add(cPanel,BorderLayout.CENTER); interFrame.setSize(100,100); desktop.add(interFrame); try { //Initially show the internal frame maximized interFrame.setMaximum(true); } catch (PropertyVetoException ex) { ex.printStackTrace(); } //this allows to handle KeyListener events cPanel.setFocusable(true); interFrame.setVisible(true); } public void run(){ //used to represent client screen size Rectangle clientScreenDim = null; //Used to read screenshots and client screen dimension ObjectInputStream ois = null; //start drawing GUI drawGUI(); try{ //Read client screen dimension ois = new ObjectInputStream(cSocket.getInputStream()); clientScreenDim =(Rectangle) ois.readObject(); }catch(IOException ex){ [50] SRTIST(I.T Dept)

Virtual Controller
ex.printStackTrace(); }catch(ClassNotFoundException ex){ ex.printStackTrace(); } //Start recieveing screenshots new ClientScreenReciever(ois,cPanel); //Start sending events to the client new ClientCommandsSender(cSocket,cPanel,clientScreenDim); } ////eg:ClientCommandSenderClass public void mouseDragged(MouseEvent e) { } public void mouseMoved(MouseEvent e) { double xScale = clientScreenDim.getWidth()/cPanel.getWidth(); System.out.println("xScale: " + xScale); double yScale = clientScreenDim.getHeight()/cPanel.getHeight(); System.out.println("yScale: " + yScale); System.out.println("Mouse Moved"); writer.println(EnumCommands.MOVE_MOUSE.getAbbrev()); writer.println((int)(e.getX() * xScale)); writer.println((int)(e.getY() * yScale)); writer.flush(); } ///Eg:client Screen Receiver class while(continueLoop){ //Recieve client screenshot and resize it to the current panel size ImageIcon imageIcon = (ImageIcon) cObjectInputStream.readObject(); System.out.println("New image recieved"); [51] SRTIST(I.T Dept)

Virtual Controller
Image image = imageIcon.getImage(); image = image.getScaledInstance(cPanel.getWidth(),cPanel.getHeight() ,Image.SCALE_FAST); //Draw the recieved screenshot Graphics graphics = cPanel.getGraphics(); graphics.drawImage(image, 0, 0, cPanel.getWidth(),cPanel.getHeight(),cPanel);

Client system is trying to connecting to server system: Enter server IP Address:


String ip = JOptionPane.showInputDialog("Please enter server IP");

Enter server Port Number:


String port = JOptionPane.showInputDialog("Please enter server port");

[52] SRTIST(I.T Dept)

Virtual Controller

10.CONCLUSION
Virtual Controller provides some very useful and general important functions in the administration tasks, in this application; The remote computer acts as client and the controlling computer acts as a server. Any number of clients can be connected to the server. The modern virtual controller achieves in terms of the existing system problems, in generally administrators are server part which waits for clients connections and per each connected client, a new frame appears showing the current client screen. When you move the mouse over the frame, these results in moving the mouse at the client side.

[53] SRTIST(I.T Dept)

Virtual Controller

11. BIBILIOGRAPHY
1. the JDK1.4 tutorial Greg Travis 2. Complete Reference Java, 2nd Edition Herbert Schlitz 3. Core Java Foundation Class Kim Topley, 4. Java Network Programming OReilly 5. JAVA how to program DEITEL & DEITEL 6. The Unified Modeling Language User Guide: GRADY BOOCH, JAMES RUMBAUGH, IVAR JACOBSON 7. Accessibility and the Swing Set, Mark Andrews, The Swing Connection, Sun Microsystems, 1999. http://java.sun.com/products/jfc/tsc/articles/accessibility/index.html 8. Coming Swing API Changes for Java 2 SDK, Standard Edition, v. 1.4, Connection, Sun Microsystems, 2001. The Swing http://java.sun.com/products/jfc/tsc/articles/merlin/index.html 9. Component Orientation in Swing, Ralph Karr 10. The Swing Connection, Sun Microsystems,1999. http://java.sun.com/products/jfc/tsc/articles/bidi/index.html 11. Core Java Foundation Classes (Core Series), Kim Topley, Prentice Hall, 1998.

[54] SRTIST(I.T Dept)

You might also like