java monitor监控_java写的监控桌面程序

这是一个使用Java编写的服务器程序,实现了通过7788端口监听客户端连接,接收到客户端发送的图像信息并在桌面显示的功能。程序利用了Eclipse SWT库来创建图形界面,展示从远程客户端接收的画面,并更新标题显示客户端的主机名和IP地址。
摘要由CSDN通过智能技术生成

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

这个是服务器程序:

import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.InetAddress;import java.net.ServerSocket;import java.net.Socket;import java.util.Date;

import org.eclipse.swt.SWT;import org.eclipse.swt.graphics.GC;import org.eclipse.swt.graphics.Image;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;

public class MonitorServer {public static void main(String[] args) throws IOException {final Display display = new Display();final Shell shell = new Shell(display, SWT.MAX|SWT.MIN|SWT.RESIZE);shell.setLayout(new GridLayout());shell.setBounds(0, 0, display.getClientArea().width,display.getClientArea().height);shell.setText("无监控客户端连接");shell.open();// 把该类和本地的端口号进行绑定 (1025-65535)int port = 7788;System.out.println("服务器端消息:服务器已经和7788端口进行了绑定");final ServerSocket server = new ServerSocket(port);System.out.println("开启服务器等待连接....");final GC gc = new GC(shell);while(!shell.isDisposed()){if (!display.readAndDispatch()){display.sleep();display.asyncExec(new Runnable(){public void run() {try {Socket client = server.accept();// 对网络计算机的远程信息的管理InetAddress address = client.getInetAddress();String clientIp = address.getHostAddress();String hostName = address.getHostName();// 使用client和客户端交流InputStream is = client.getInputStream();OutputStream os = client.getOutputStream();Image img = new Image(display, is);gc.drawImage(img,0,0,img.getBounds().width,img.getBounds().height,0, 0, shell.getBounds().width,shell.getBounds().height);shell.setText("监控客户端:["+hostName+","+clientIp+"] 当前时间"+new Date().toLocaleString());//gc.drawString("监控客户端:["+hostName+","+clientIp+"] 当前时间"+new Date().toLocaleString(), 0, 0);img.dispose();os.close();is.close();} catch (Exception e) {e.printStackTrace();}}});}}System.out.println("服务器已经关闭");server.close();gc.dispose();display.dispose();}}

就是一个main方法,直接运行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值