Lan Remote Computer Monitoring Program

Source: Internet
Author: User
Tags ad server

 


Lan Remote Computer Monitoring Program
Including server and client
Run the server program on a machine
The client runs the client program.
Dynamically monitors server screens
Transfers mouse and keyboard events to normal operations
Running Environment: jdk1.4.1 (Handling of scroll wheel events)
My three machines are
Win2000 ad server
Winxp sion
Redhat in linux 8.0
Can run the server and client, and can work
Supports multiple clients on one server.

Server Source Code:

// Package com. zms. remotecontrol;
Import java. awt. BorderLayout;
Import java. awt. Dimension;
Import java. awt. Rectangle;
Import java. awt. Robot;
Import java. awt. Toolkit;
Import java. awt. event. ActionEvent;
Import java. awt. event. ActionListener;
Import java. awt. event. WindowAdapter;
Import java. awt. event. javaswevent;
Import java. awt. image. BufferedImage;
Import java. io. ByteArrayOutputStream;
Import java.net. DatagramPacket;
Import java.net. DatagramSocket;
Import java.net. SocketAddress;
Import javax. swing. JButton;
Import javax. swing. JFrame;
Import javax. swing. UIManager;
Import com.sun.image.codec.jpeg. Unzip codec;
Import com.sun.image.codec.jpeg. Unzip encodeparam;
Import com.sun.image.codec.jpeg. encode imageencoder;

Public class ServerTest extends Thread {
Private DatagramSocket socket;
Public static final int PORT = 5000;
Public static final int MAX = 102400;
Public boolean end;
Private Robot robot;
Private Toolkit toolkit;
Public ServerTest () throws Exception {
Robot = new Robot ();
Toolkit = Toolkit. getdefatooltoolkit ();
This. socket = new DatagramSocket (PORT );
Socket. setSendBufferSize (MAX );
End = false;
}
Private void sendScreen (SocketAddress address ){
Try {
BufferedImage image = robot. createScreenCapture (new Rectangle (toolkit. getScreenSize ()));
ByteArrayOutputStream output = new ByteArrayOutputStream ();
Required encodeparam param = required codec. getDefaultJPEGEncodeParam (image );
Param. setQuality (0.1f, false );
Required imageencoder encoder = required codec. createJPEGEncoder (output, param );
Encoder. encode (image );
Encoder. getOutputStream (). close ();
DatagramPacket packet = new DatagramPacket (output. toByteArray (), output. size
(), Address );
This. socket. send (packet );
} Catch (Exception e ){
E. printStackTrace ();
}
}
Public void run (){
Byte [] bytes = new byte [1, 1020];
While (! End ){
Try {
Required rampacket packet = new DatagramPacket (bytes, bytes. length );
This. socket. receive (packet );
String command = new String (packet. getData (), packet. getOffset (), 20). trim ();
If (command. Revoke signorecase (REFRESH )){
SendScreen (packet. getSocketAddress ());
} Else {
Byte [] the = packet. getData ();
Int n = packet. getOffset ();
Int x = Integer. parseInt (new String (the, n + 20, 10). trim ());
Int y = Integer. parseInt (new String (the, n + 30,10). trim ());
Int button = Integer. parseInt (new String (the, n + 40, 10). trim ());
If (command. inclusignorecase (MousePressed )){
Robot. mousePress (button );
} Else if (command. inclusignorecase (MouseReleased )){
Robot. mouseRelease (button );
} Else if (command. inclusignorecase (MouseMoved )){
Robot. mouseMove (x, y );
} Else if (command. inclusignorecase (MouseWheel )){
Robot. mouseWheel (button );
} Else if (command. inclusignorecase (KeyPressed )){
Robot. keyPress (x );
} Else if (command. inclusignorecase (KeyReleased )){
Robot. keyRelease (x );
}
}
} Catch (Exception e ){
Try {
Thread. sleep (100 );
} Catch (Exception ex ){
}
}
}
}
Public void close (){
End = true;
This. socket. close ();
}
Public static void main (String [] args ){
ServerTest one = null;
Try {
UIManager. setLookAndFeel (UIManager. getSystemLookAndFeelClassName ());
JFrame frame = new JFrame (Remote Control Server );
Frame. getContentPane (). setLayout (new BorderLayout ());
Frame. setSize (240,80 );
JButton exit = new JButton (Exit );
Frame. getContentPane (). add (exit, BorderLayout. CENTER );
Dimension screen = Toolkit. getdefatooltoolkit (). getScreenSize ();
Dimension a = frame. getSize ();
Frame. setLocation (screen. width-a.width)/2, (screen. height-a.height)/2 );
One = new ServerTest ();
One. start ();
Final ServerTest the = one;
Exit. addActionListener (new ActionListener (){
Public void actionreceivmed (ActionEvent e ){
The. close ();
System. exit (0 );
}
});
Frame. addWindowListener (new WindowAdapter (){
Public void windowClosing (WindowEvent e ){
The. close ();
System. exit (0 );
}
});
Frame. setVisible (true );
} Catch (Exception e ){
E. printStackTrace ();
If (one! = Null ){
One. close ();
}
System. exit (0 );
}
}
}

The client source code has been compiled and is being improved. You are welcome to contact us. The source code has been published on my homepage!


// Client source code:
/*
* Created on 2003-3-25
*
* To change this generated comment go
* Window> Preferences> Java> Code Generation> Code and Comments
Usage:
First run the server-side program on the server
Run the client program on the client (do not run on a machine, you will find the mouse strange)
Right-click the center area of the client, click the menu item, and enter the server address.
OK
Let me continue to improve
*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.