该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
这个是服务器程序:
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方法,直接运行