├── Demo ├── 1.jpg ├── 2.jpg ├── 3.jpg ├── YiDaoCaiDemoWeek6.zip └── YiDaoCaiDemoWeek7.zip ├── json.jar ├── 文档1.docx ├── 架构图1.jpg ├── 架构图2.jpg ├── bin ├── image │ ├── set.png │ ├── prtSc.png │ ├── taskView.png │ ├── tranFile.png │ └── shutdown_up.png ├── CommonClass │ ├── XMLUtil.class │ ├── Information.class │ ├── DesktopRemoteType.class │ └── SocketStatusListener.class ├── commonUI │ ├── watchFrame.class │ ├── watchFrame$1.class │ └── watchFrame$Screen.class ├── DesktopServerUI │ ├── FileFrame.class │ ├── PCPanel$1.class │ ├── PCPanel$2.class │ ├── PCPanel$3.class │ ├── PCPanel$4.class │ ├── PCPanel$5.class │ ├── PCPanel.class │ ├── taskViewFrame.class │ ├── ServerMainFrame.class │ ├── FileFrame$RunSend.class │ ├── ServerMainFrame$1.class │ ├── ServerMainFrame$2.class │ ├── ServerMainFrame$3.class │ ├── FileFrame$FileAction.class │ ├── ServerMainFrame$Action.class │ ├── taskViewFrame$ProcessView.class │ ├── DesktopServerRaiseHandFrame.class │ ├── FileFrame$WindowsFileChooser.class │ ├── taskViewFrame$ProcessView$1.class │ └── taskViewFrame$ProcessView$Action.class ├── DesktopClientProcess │ ├── Client.class │ ├── ClientShot.class │ ├── Client$FileReceive.class │ ├── ClientSocketHandler.class │ ├── ClientShot$Boardcast.class │ ├── ClientSocketHandler$ReaderTask.class │ └── ClientSocketHandler$WriterTask.class ├── DesktopServerProcess │ ├── Server.class │ ├── Server$1.class │ ├── ServerThread.class │ ├── Server$openSocket.class │ ├── ServerShotHandler.class │ ├── ServerSocketHandler.class │ ├── ServerShotHandler$Screen.class │ ├── ServerShotHandler$Broadcast.class │ ├── ServerSocketHandler$SendFile.class │ ├── ServerSocketHandler$ReaderTask.class │ ├── ServerSocketHandler$WriterTask.class │ └── ServerShotHandler$Broadcast$Send.class └── DesktopClientUI │ ├── ClientDialogUI.class │ ├── ClientDialogUI$1.class │ ├── ClientDialogUI$1$1.class │ └── ClientDialogUI$Action.class ├── src ├── image │ ├── set.png │ ├── prtSc.png │ ├── taskView.png │ ├── tranFile.png │ └── shutdown_up.png ├── CommonClass │ ├── SocketStatusListener.java │ ├── DesktopRemoteType.java │ ├── XMLUtil.java │ └── Information.java ├── DesktopServerProcess │ ├── ServerThread.java │ ├── Server.java │ ├── ServerShotHandler.java │ └── ServerSocketHandler.java ├── DesktopServerUI │ ├── DesktopServerRaiseHandFrame.java │ ├── PCPanel.java │ ├── taskViewFrame.java │ ├── FileFrame.java │ └── ServerMainFrame.java ├── commonUI │ └── watchFrame.java ├── DesktopClientProcess │ ├── ClientShot.java │ ├── Client.java │ └── ClientSocketHandler.java └── DesktopClientUI │ └── ClientDialogUI.java ├── config.xml ├── .classpath ├── README.md ├── .project └── .settings └── org.eclipse.jdt.core.prefs /Demo/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/Demo/1.jpg -------------------------------------------------------------------------------- /Demo/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/Demo/2.jpg -------------------------------------------------------------------------------- /Demo/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/Demo/3.jpg -------------------------------------------------------------------------------- /json.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/json.jar -------------------------------------------------------------------------------- /文档1.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/文档1.docx -------------------------------------------------------------------------------- /架构图1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/架构图1.jpg -------------------------------------------------------------------------------- /架构图2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/架构图2.jpg -------------------------------------------------------------------------------- /bin/image/set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/image/set.png -------------------------------------------------------------------------------- /src/image/set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/src/image/set.png -------------------------------------------------------------------------------- /bin/image/prtSc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/image/prtSc.png -------------------------------------------------------------------------------- /config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 172.25.240.19 4 | -------------------------------------------------------------------------------- /src/image/prtSc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/src/image/prtSc.png -------------------------------------------------------------------------------- /bin/image/taskView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/image/taskView.png -------------------------------------------------------------------------------- /bin/image/tranFile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/image/tranFile.png -------------------------------------------------------------------------------- /src/image/taskView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/src/image/taskView.png -------------------------------------------------------------------------------- /src/image/tranFile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/src/image/tranFile.png -------------------------------------------------------------------------------- /bin/image/shutdown_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/image/shutdown_up.png -------------------------------------------------------------------------------- /src/image/shutdown_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/src/image/shutdown_up.png -------------------------------------------------------------------------------- /Demo/YiDaoCaiDemoWeek6.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/Demo/YiDaoCaiDemoWeek6.zip -------------------------------------------------------------------------------- /Demo/YiDaoCaiDemoWeek7.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/Demo/YiDaoCaiDemoWeek7.zip -------------------------------------------------------------------------------- /bin/CommonClass/XMLUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/CommonClass/XMLUtil.class -------------------------------------------------------------------------------- /bin/commonUI/watchFrame.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/commonUI/watchFrame.class -------------------------------------------------------------------------------- /bin/commonUI/watchFrame$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/commonUI/watchFrame$1.class -------------------------------------------------------------------------------- /bin/CommonClass/Information.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/CommonClass/Information.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/FileFrame.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/FileFrame.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/PCPanel$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/PCPanel$1.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/PCPanel$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/PCPanel$2.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/PCPanel$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/PCPanel$3.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/PCPanel$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/PCPanel$4.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/PCPanel$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/PCPanel$5.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/PCPanel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/PCPanel.class -------------------------------------------------------------------------------- /bin/DesktopClientProcess/Client.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopClientProcess/Client.class -------------------------------------------------------------------------------- /bin/DesktopServerProcess/Server.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerProcess/Server.class -------------------------------------------------------------------------------- /bin/commonUI/watchFrame$Screen.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/commonUI/watchFrame$Screen.class -------------------------------------------------------------------------------- /bin/CommonClass/DesktopRemoteType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/CommonClass/DesktopRemoteType.class -------------------------------------------------------------------------------- /bin/DesktopClientUI/ClientDialogUI.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopClientUI/ClientDialogUI.class -------------------------------------------------------------------------------- /bin/DesktopServerProcess/Server$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerProcess/Server$1.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/taskViewFrame.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/taskViewFrame.class -------------------------------------------------------------------------------- /bin/CommonClass/SocketStatusListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/CommonClass/SocketStatusListener.class -------------------------------------------------------------------------------- /bin/DesktopClientProcess/ClientShot.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopClientProcess/ClientShot.class -------------------------------------------------------------------------------- /bin/DesktopClientUI/ClientDialogUI$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopClientUI/ClientDialogUI$1.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/ServerMainFrame.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/ServerMainFrame.class -------------------------------------------------------------------------------- /bin/DesktopClientUI/ClientDialogUI$1$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopClientUI/ClientDialogUI$1$1.class -------------------------------------------------------------------------------- /bin/DesktopServerProcess/ServerThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerProcess/ServerThread.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/FileFrame$RunSend.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/FileFrame$RunSend.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/ServerMainFrame$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/ServerMainFrame$1.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/ServerMainFrame$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/ServerMainFrame$2.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/ServerMainFrame$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/ServerMainFrame$3.class -------------------------------------------------------------------------------- /bin/DesktopClientUI/ClientDialogUI$Action.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopClientUI/ClientDialogUI$Action.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/FileFrame$FileAction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/FileFrame$FileAction.class -------------------------------------------------------------------------------- /bin/DesktopClientProcess/Client$FileReceive.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopClientProcess/Client$FileReceive.class -------------------------------------------------------------------------------- /bin/DesktopClientProcess/ClientSocketHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopClientProcess/ClientSocketHandler.class -------------------------------------------------------------------------------- /bin/DesktopServerProcess/Server$openSocket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerProcess/Server$openSocket.class -------------------------------------------------------------------------------- /bin/DesktopServerProcess/ServerShotHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerProcess/ServerShotHandler.class -------------------------------------------------------------------------------- /bin/DesktopServerProcess/ServerSocketHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerProcess/ServerSocketHandler.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/ServerMainFrame$Action.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/ServerMainFrame$Action.class -------------------------------------------------------------------------------- /bin/DesktopClientProcess/ClientShot$Boardcast.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopClientProcess/ClientShot$Boardcast.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/taskViewFrame$ProcessView.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/taskViewFrame$ProcessView.class -------------------------------------------------------------------------------- /bin/DesktopServerProcess/ServerShotHandler$Screen.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerProcess/ServerShotHandler$Screen.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/DesktopServerRaiseHandFrame.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/DesktopServerRaiseHandFrame.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/FileFrame$WindowsFileChooser.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/FileFrame$WindowsFileChooser.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/taskViewFrame$ProcessView$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/taskViewFrame$ProcessView$1.class -------------------------------------------------------------------------------- /bin/DesktopServerProcess/ServerShotHandler$Broadcast.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerProcess/ServerShotHandler$Broadcast.class -------------------------------------------------------------------------------- /bin/DesktopServerProcess/ServerSocketHandler$SendFile.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerProcess/ServerSocketHandler$SendFile.class -------------------------------------------------------------------------------- /bin/DesktopServerUI/taskViewFrame$ProcessView$Action.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerUI/taskViewFrame$ProcessView$Action.class -------------------------------------------------------------------------------- /bin/DesktopClientProcess/ClientSocketHandler$ReaderTask.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopClientProcess/ClientSocketHandler$ReaderTask.class -------------------------------------------------------------------------------- /bin/DesktopClientProcess/ClientSocketHandler$WriterTask.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopClientProcess/ClientSocketHandler$WriterTask.class -------------------------------------------------------------------------------- /bin/DesktopServerProcess/ServerSocketHandler$ReaderTask.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerProcess/ServerSocketHandler$ReaderTask.class -------------------------------------------------------------------------------- /bin/DesktopServerProcess/ServerSocketHandler$WriterTask.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerProcess/ServerSocketHandler$WriterTask.class -------------------------------------------------------------------------------- /bin/DesktopServerProcess/ServerShotHandler$Broadcast$Send.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiDaoCai/RemoteDesktop/HEAD/bin/DesktopServerProcess/ServerShotHandler$Broadcast$Send.class -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RemoteDesktop 2 | 远程桌面监控系统 3 | ### 用于学校实验室内教师电脑对学生机器的监视、控制等管理。 4 | ### 有屏幕广播、屏幕监视、对话、文件互传、进程关闭等功能。 5 | ## 用 Java Socket实现。 6 | ### 教师端界面 7 | ![](https://github.com/YiDaoCai/RemoteDesktop/blob/master/Demo/1.jpg) 8 | 9 | ### 学生端界面 10 | ![](https://github.com/YiDaoCai/RemoteDesktop/blob/master/Demo/2.jpg) 11 | 12 | ### 学生机上线后教师端的界面 13 | ![](https://github.com/YiDaoCai/RemoteDesktop/blob/master/Demo/3.jpg) 14 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | RDDD 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/CommonClass/SocketStatusListener.java: -------------------------------------------------------------------------------- 1 | package CommonClass; 2 | 3 | 4 | import java.io.IOException; 5 | import java.net.Socket; 6 | 7 | public interface SocketStatusListener 8 | { 9 | public static final int STATUS_OPEN = 0x01<<0; 10 | public static final int STATUS_CLOSE = 0x01<<1; 11 | public static final int STATUS_RESET = 0x01<<2; 12 | public static final int STATUS_PIP_BROKEN = 0x01<<3; 13 | public static final int STATUS_UNKOWN = 0x01<<4; 14 | 15 | public void onSocketStatusChanged(Socket socket,int status,IOException e); 16 | } -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.6 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.6 12 | -------------------------------------------------------------------------------- /src/CommonClass/DesktopRemoteType.java: -------------------------------------------------------------------------------- 1 | package CommonClass; 2 | //定义不同功能使用不同端口 3 | public class DesktopRemoteType { 4 | 5 | private DesktopRemoteType (String type, int port) { 6 | this.type = type; 7 | this.port = port; 8 | } 9 | 10 | public String getType() { 11 | return type; 12 | } 13 | 14 | public int getPort() { 15 | return port; 16 | } 17 | 18 | private String type; 19 | private int port; 20 | 21 | 22 | public static final DesktopRemoteType ServerFile = new DesktopRemoteType("ServerFile", 1234); 23 | public static final DesktopRemoteType OtherType = new DesktopRemoteType("Other", 5678); 24 | public static final DesktopRemoteType ServerShot = new DesktopRemoteType("ServerShot", 3456); 25 | public static final DesktopRemoteType ClientShot = new DesktopRemoteType("ClientShot", 6543); 26 | public static final DesktopRemoteType ClientFile = new DesktopRemoteType("ClientFile", 6789); 27 | } -------------------------------------------------------------------------------- /src/DesktopServerProcess/ServerThread.java: -------------------------------------------------------------------------------- 1 | package DesktopServerProcess; 2 | //线程vo 3 | import java.io.*; 4 | import java.net.Socket; 5 | import java.util.HashMap; 6 | import java.util.Iterator; 7 | import java.util.Map; 8 | import java.util.Map.Entry; 9 | 10 | import CommonClass.Information; 11 | 12 | 13 | 14 | public class ServerThread extends ServerSocketHandler { 15 | private static Map UserList = new HashMap(); 16 | //private BufferedReader is; 17 | public ServerThread(Socket c) throws IOException { 18 | super(c); 19 | } 20 | public void setClient(Socket c) { 21 | this.socket = c; 22 | } 23 | public Socket getSocket() { 24 | return this.socket; 25 | } 26 | 27 | public static int getUserList() { 28 | return UserList.size(); 29 | } 30 | public static ServerThread getServerThread(String ip) { 31 | return UserList.get(ip); 32 | } 33 | public static Iterator> getUser() { 34 | return UserList.entrySet().iterator(); 35 | } 36 | public static void addUserList(String intelAdd, ServerThread st) { 37 | UserList.put(intelAdd, st); 38 | } 39 | public static void removeUserList(String string) { 40 | UserList.remove(string); 41 | } 42 | /** 43 | * @return 44 | * 向客户端发送消息 45 | */ 46 | public void sendMessage(Information info) { 47 | writer.send(info.toString()); 48 | //将从系统标准输入读入的字符串输出到Server 49 | } 50 | } -------------------------------------------------------------------------------- /src/CommonClass/XMLUtil.java: -------------------------------------------------------------------------------- 1 | package CommonClass; 2 | //获取xml里的ip 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | 8 | import javax.xml.parsers.DocumentBuilder; 9 | import javax.xml.parsers.DocumentBuilderFactory; 10 | 11 | import org.w3c.dom.Document; 12 | import org.w3c.dom.Node; 13 | import org.w3c.dom.NodeList; 14 | 15 | public class XMLUtil { 16 | 17 | public static boolean exist() { 18 | File f = new File("config.xml"); 19 | return f.exists(); 20 | } 21 | 22 | public static void createXML(String ip) { 23 | String out = "\r\n\r\n " + ip + "\r\n"; 24 | String filename = "config.xml"; 25 | File f = new File(filename); 26 | if(!f.exists()) { 27 | try { 28 | f.createNewFile(); 29 | } catch (IOException e) { 30 | // TODO Auto-generated catch block 31 | e.printStackTrace(); 32 | } 33 | } 34 | FileOutputStream fos; 35 | try { 36 | fos = new FileOutputStream(f); 37 | fos.write(out.getBytes()); 38 | fos.flush(); 39 | fos.close(); 40 | } catch (FileNotFoundException e) { 41 | // TODO Auto-generated catch block 42 | e.printStackTrace(); 43 | } catch (IOException e) { 44 | // TODO Auto-generated catch block 45 | e.printStackTrace(); 46 | } 47 | 48 | } 49 | 50 | public static String getBean(String configName) { 51 | try { 52 | // 53 | DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); 54 | DocumentBuilder builder = dFactory.newDocumentBuilder(); 55 | Document doc = builder.parse(new File("config.xml")); 56 | 57 | // 58 | NodeList nl = doc.getElementsByTagName(configName); 59 | Node classNode = nl.item(0).getFirstChild(); 60 | return classNode.getNodeValue(); 61 | 62 | } catch (Exception e) { 63 | // TODO: handle exception 64 | e.printStackTrace(); 65 | return null; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/DesktopServerUI/DesktopServerRaiseHandFrame.java: -------------------------------------------------------------------------------- 1 | package DesktopServerUI; 2 | //举手窗口 3 | import java.awt.*; 4 | 5 | import javax.swing.*; 6 | 7 | public class DesktopServerRaiseHandFrame { 8 | private JFrame frm; 9 | private JLabel text; 10 | private int width, height; 11 | private Dimension screenSize; 12 | 13 | private static DesktopServerRaiseHandFrame raisehandframe; 14 | 15 | public static DesktopServerRaiseHandFrame getFrame() { 16 | if(raisehandframe == null) { 17 | try { 18 | raisehandframe = new DesktopServerRaiseHandFrame(); 19 | } catch (InterruptedException e) { 20 | // TODO Auto-generated catch block 21 | e.printStackTrace(); 22 | } 23 | } 24 | return raisehandframe; 25 | } 26 | 27 | private DesktopServerRaiseHandFrame() throws InterruptedException { 28 | width = 200; 29 | height = 80; 30 | frm = new JFrame(); 31 | text = new JLabel(); 32 | // 加上这一句就可以显示一个仅有关闭,最小化,最大化的按钮的Frame了 33 | screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 34 | 35 | // 再加上这一句就可以显示一个在左上角,拥有指定大小的Frame了 36 | frm.setSize(width, height); 37 | frm.setLocation(screenSize.width - width, screenSize.height - height 38 | - 40); 39 | frm.setResizable(false); 40 | 41 | // 如果没有这一句,在点击关闭Frame的时候程序其实还是在执行状态中的,加上这一句才算是真正的把资源释放掉了 42 | //frm.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 43 | 44 | Container c = frm.getContentPane(); 45 | 46 | JPanel panel = new JPanel(); 47 | c.add(panel, BorderLayout.CENTER); 48 | // panel.setVisible(true); 49 | text.setFont(new Font("宋体", Font.BOLD, 24)); 50 | panel.add(text); 51 | } 52 | 53 | public void setText(String value) throws InterruptedException { 54 | text.setText(value); 55 | width = value.length() * 30; 56 | reSize(); 57 | frm.setVisible(true); 58 | Thread.sleep(3000); 59 | frm.setVisible(false); 60 | } 61 | 62 | private void reSize() { 63 | frm.setSize(width, height); 64 | frm.setLocation(screenSize.width - width, screenSize.height - height 65 | - 40); 66 | } 67 | 68 | /*public static void main(String[] args) { 69 | // 现在创建了一个对象,不过什么都显示不出来 70 | try { 71 | DesktopServerRaiseHandFrame d = new DesktopServerRaiseHandFrame(); 72 | d.setText("有同学举手"); 73 | } catch (InterruptedException e) { 74 | // TODO Auto-generated catch block 75 | e.printStackTrace(); 76 | } 77 | 78 | }*/ 79 | 80 | } -------------------------------------------------------------------------------- /src/CommonClass/Information.java: -------------------------------------------------------------------------------- 1 | package CommonClass; 2 | //打包成json 3 | import java.util.*; 4 | 5 | import org.json.*; 6 | 7 | public class Information { 8 | private String type; 9 | private String fromAdd; 10 | private String toAdd; 11 | private String content; 12 | private long date; 13 | 14 | public String getType() { 15 | return type; 16 | } 17 | public String getFromAdd() { 18 | return fromAdd; 19 | } 20 | public String getContent() { 21 | return content; 22 | } 23 | public long getDate() { 24 | return date; 25 | } 26 | public Information(String json) { 27 | try { 28 | JSONObject Json = new JSONObject(json); 29 | Map result = new HashMap(); 30 | Iterator iterator = Json.keys(); 31 | String key; 32 | while(iterator.hasNext()) { 33 | key = (String)iterator.next(); 34 | result.put(key, Json.get(key)); 35 | } 36 | type = result.get("type").toString(); 37 | fromAdd = result.get("fromAdd").toString(); 38 | date = (Long) result.get("date"); 39 | toAdd = result.get("toAdd").toString(); 40 | //content = new String("hello"); 41 | if(!type.equals("raisehand")) { 42 | content = result.get("content").toString(); 43 | } 44 | } catch (JSONException e) { 45 | // TODO Auto-generated catch block 46 | e.printStackTrace(); 47 | } 48 | 49 | } 50 | public Information(String type, String fromAdd, String content, String toAdd) { 51 | this.type = type; 52 | this.fromAdd = fromAdd; 53 | this.content = content; 54 | this.date = (new Date()).getTime(); 55 | this.toAdd = toAdd; 56 | } 57 | public static Information createRaiseHand(String fromAdd) { 58 | return new Information("raisehand", fromAdd, null, "Server"); 59 | } 60 | public static Information createOperator(String type, String cmd) { 61 | return new Information(type, "Server", cmd, "Server"); 62 | } 63 | public static Information createSession(String fromAdd, String content, String to) { 64 | return new Information("session", fromAdd, content, to); 65 | } 66 | public String toString() { 67 | JSONObject json = new JSONObject(); 68 | try { 69 | json.put("type", type); 70 | json.put("fromAdd", fromAdd); 71 | json.put("toAdd", toAdd); 72 | json.put("content", content); 73 | json.put("date", date); 74 | } catch (JSONException e) { 75 | // TODO Auto-generated catch block 76 | e.printStackTrace(); 77 | } 78 | return json.toString(); 79 | } 80 | public String getToAdd() { 81 | return toAdd; 82 | } 83 | public void setToAdd(String toAdd) { 84 | this.toAdd = toAdd; 85 | } 86 | } 87 | 88 | -------------------------------------------------------------------------------- /src/commonUI/watchFrame.java: -------------------------------------------------------------------------------- 1 | package commonUI; 2 | //教师/学生端远程监视(视频)的窗口 3 | import java.awt.*; 4 | import java.awt.event.WindowAdapter; 5 | import java.awt.event.WindowEvent; 6 | 7 | import javax.swing.*; 8 | 9 | 10 | public class watchFrame extends JFrame { 11 | private String ip; 12 | private static final long serialVersionUID = 1L; 13 | private String inetAddress; 14 | private static watchFrame frame; 15 | private boolean statu = false; 16 | private Screen sc; 17 | private Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 18 | public static watchFrame getFrame() { 19 | if(frame == null) 20 | frame = new watchFrame(); 21 | return frame; 22 | } 23 | public String getInetAddress() { 24 | return inetAddress; 25 | } 26 | public boolean isVis() { 27 | return statu; 28 | } 29 | public void setInetAddress(String ineladdress) { 30 | inetAddress = ineladdress; 31 | } 32 | private watchFrame() { 33 | super(); 34 | this.setSize(screenSize.width*8/10, screenSize.height*8/10); 35 | sc = new Screen(); 36 | Container c = this.getContentPane(); 37 | c.setLayout(new BorderLayout()); 38 | c.add(sc, SwingConstants.CENTER); 39 | this.addWindowListener(new WindowAdapter(){ 40 | public void windowClosing(WindowEvent we){ 41 | setStatu(false); 42 | } 43 | }); 44 | } 45 | 46 | public void setStatu(boolean statu) { 47 | this.statu = statu; 48 | setVisible(statu); 49 | } 50 | public void paint(Image cimage) { 51 | this.sc.setImage(cimage); 52 | this.sc.repaint(); 53 | } 54 | public Dimension getScreenSize() { 55 | return screenSize; 56 | } 57 | public String getIp() { 58 | return ip; 59 | } 60 | 61 | public void setIp(String ip) { 62 | this.ip = ip; 63 | setStatu(true); 64 | setTitle("远程监视 :" + ip); 65 | } 66 | 67 | class Screen extends JPanel { 68 | 69 | private static final long serialVersionUID = 1L; 70 | private Image cimage; 71 | 72 | public void setImage(Image cimage) { 73 | this.cimage = cimage; 74 | } 75 | public Screen() { 76 | super(); 77 | this.setLayout(null); 78 | } 79 | 80 | public void paint(Graphics g) { 81 | super.paint(g); 82 | Graphics2D g2 = (Graphics2D) g; 83 | g2.drawImage(cimage, 0, 0, null); 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /src/DesktopServerUI/PCPanel.java: -------------------------------------------------------------------------------- 1 | package DesktopServerUI; 2 | //桌面监视的panel以及监听器 3 | import java.awt.BorderLayout; 4 | import java.awt.Dimension; 5 | import java.awt.event.ActionEvent; 6 | import java.awt.event.ActionListener; 7 | import java.awt.event.InputEvent; 8 | import java.awt.event.MouseAdapter; 9 | import java.awt.event.MouseEvent; 10 | import java.net.Socket; 11 | 12 | import javax.swing.AbstractAction; 13 | import javax.swing.ImageIcon; 14 | import javax.swing.JButton; 15 | import javax.swing.JCheckBox; 16 | import javax.swing.JMenuItem; 17 | import javax.swing.JPanel; 18 | import javax.swing.JPopupMenu; 19 | 20 | 21 | import commonUI.watchFrame; 22 | 23 | import CommonClass.Information; 24 | import DesktopServerProcess.ServerThread; 25 | 26 | @SuppressWarnings("serial") 27 | public class PCPanel extends JPanel { 28 | private JButton scan; 29 | private JCheckBox ip; 30 | private Socket client; 31 | private JPopupMenu popup = new JPopupMenu(); 32 | public PCPanel() { 33 | super(new BorderLayout()); 34 | scan = new JButton(); 35 | scan.setPreferredSize(new Dimension(200, 150)); 36 | ip = new JCheckBox("10.0.0.1"); 37 | add(scan, BorderLayout.CENTER); 38 | add(ip, BorderLayout.SOUTH); 39 | setVisible(false); 40 | createPopMenu(); 41 | //scan.setIcon(new ImageIcon("D:\\receive\\Hello0.jpg")); 42 | } 43 | public void setIcon(ImageIcon ii) { 44 | scan.setIcon(ii); 45 | } 46 | public void setClient(Socket s) { 47 | setVisible(true); 48 | client = s; 49 | ip.setText(s.getInetAddress().getHostAddress()); 50 | } 51 | public void addActionListener(ActionListener al) { 52 | scan.addActionListener(al); 53 | } 54 | public boolean isSelected() { 55 | return ip.isSelected(); 56 | } 57 | public String getIp() { 58 | return ip.getText(); 59 | } 60 | public void setSelected(boolean ok) { 61 | ip.setSelected(ok); 62 | } 63 | public void createPopMenu() { 64 | popup.add(new JMenuItem(new AbstractAction("发文件") { 65 | 66 | @Override 67 | public void actionPerformed(ActionEvent e) { 68 | // TODO Auto-generated method stub 69 | ServerMainFrame.ClearIp(); 70 | ServerMainFrame.add(client.getInetAddress().getHostAddress()); 71 | FileFrame.getFrame().setVis(true); 72 | } 73 | })); 74 | popup.add(new JMenuItem(new AbstractAction("关机") { 75 | 76 | @Override 77 | public void actionPerformed(ActionEvent e) { 78 | // TODO Auto-generated method stub 79 | ServerThread.getServerThread(ip.getText()).sendMessage(new Information("cmd", "Server", "shutdown -s -t 0", ip.getText())); 80 | } 81 | })); 82 | popup.add(new JMenuItem(new AbstractAction("进程监控") { 83 | 84 | @Override 85 | public void actionPerformed(ActionEvent e) { 86 | // TODO Auto-generated method stub 87 | taskViewFrame.getFrame().setIp(ip.getText()); 88 | ServerThread.getServerThread(ip.getText()).sendMessage(new Information("tasklist", "Server", "tasklist", ip.getText())); 89 | } 90 | })); 91 | popup.add(new JMenuItem(new AbstractAction("对话") { 92 | 93 | @Override 94 | public void actionPerformed(ActionEvent e) { 95 | // TODO Auto-generated method stub 96 | ServerMainFrame.getFrame().setSelected(ip.getText()); 97 | } 98 | })); 99 | scan.addMouseListener(new MouseAdapter(){ 100 | public void mousePressed(MouseEvent e) { 101 | int mods = e.getModifiers(); 102 | int iClickCount = e.getClickCount(); 103 | 104 | if ((mods & InputEvent.BUTTON3_MASK) != 0) { 105 | // 判断是鼠标右键 106 | // 弹出菜单 107 | popup.show(e.getComponent(), e.getX(), e.getY()); 108 | } else if(iClickCount>=2) { //判断是否是双击 109 | watchFrame.getFrame().setIp(ip.getText()); 110 | } 111 | 112 | } 113 | }); 114 | } 115 | } -------------------------------------------------------------------------------- /src/DesktopClientProcess/ClientShot.java: -------------------------------------------------------------------------------- 1 | package DesktopClientProcess; 2 | //学生端发送图片流 3 | import java.awt.*; 4 | import java.awt.image.BufferedImage; 5 | import java.io.*; 6 | import java.net.*; 7 | import java.util.zip.*; 8 | 9 | import javax.imageio.ImageIO; 10 | 11 | 12 | import CommonClass.DesktopRemoteType; 13 | 14 | import com.sun.image.codec.jpeg.JPEGCodec; 15 | import commonUI.watchFrame; 16 | 17 | public class ClientShot extends Thread { 18 | private Dimension screenSize; 19 | private Rectangle rectangle; 20 | private Robot robot; 21 | private ServerSocket shotsocket; 22 | private watchFrame BCFrame; 23 | public ClientShot() { 24 | screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 25 | rectangle = new Rectangle(screenSize);// 可以指定捕获屏幕区域 26 | BCFrame = watchFrame.getFrame(); 27 | BCFrame.setTitle("教师"); 28 | BCFrame.setSize(screenSize); 29 | BCFrame.setExtendedState(Frame.MAXIMIZED_BOTH); 30 | //BCFrame.setResizable(false); 31 | try { 32 | robot = new Robot(); 33 | shotsocket = new ServerSocket(DesktopRemoteType.ClientShot.getPort()); 34 | new Boardcast().start(); 35 | this.start(); 36 | } catch (Exception e) { 37 | e.printStackTrace(); 38 | System.out.println(e); 39 | } 40 | } 41 | 42 | public synchronized void run() { 43 | ZipOutputStream os = null; 44 | Socket socket = null; 45 | while (true) { 46 | try { 47 | socket = new Socket(Client.getServerAddress(), DesktopRemoteType.ServerShot.getPort());// 连接远程IP 48 | BufferedImage image = robot.createScreenCapture(rectangle);// 捕获制定屏幕矩形区域 49 | os = new ZipOutputStream(socket.getOutputStream());// 加入压缩流 50 | 51 | os.setLevel(9); 52 | os.putNextEntry(new ZipEntry("test.jpg")); 53 | JPEGCodec.createJPEGEncoder(os).encode(image);// 图像编码成JPEG 54 | os.close(); 55 | Thread.sleep(500);// 每秒2帧 56 | } catch (Exception e) { 57 | e.printStackTrace(); 58 | } finally { 59 | if (os != null) { 60 | try { 61 | os.close(); 62 | } catch (Exception ioe) { 63 | } 64 | } 65 | if (socket != null) { 66 | 67 | try { 68 | socket.close(); 69 | } catch (IOException e) { 70 | } 71 | } 72 | } 73 | } 74 | } 75 | public class Boardcast extends Thread { 76 | /** 77 | * @return 接收来自服务端的屏幕广播 78 | */ 79 | public void run() { 80 | Socket client; 81 | Image cimage; 82 | while (true) { 83 | try { 84 | client = shotsocket.accept(); 85 | watchFrame.getFrame().setVisible(true); 86 | ZipInputStream zis = new ZipInputStream(client.getInputStream()); 87 | zis.getNextEntry(); 88 | cimage = ImageIO.read(zis);// 把ZIP流转换为图片 89 | int width = watchFrame.getFrame().getWidth(); 90 | int height = watchFrame.getFrame().getHeight(); 91 | cimage = cimage.getScaledInstance(width, height, Image.SCALE_FAST); 92 | watchFrame.getFrame().paint(cimage); 93 | } catch (Exception e) { 94 | e.printStackTrace(); 95 | } 96 | } 97 | } 98 | } 99 | 100 | } -------------------------------------------------------------------------------- /src/DesktopServerUI/taskViewFrame.java: -------------------------------------------------------------------------------- 1 | package DesktopServerUI; 2 | //进程监控界面 3 | import java.awt.Container; 4 | import java.awt.Dimension; 5 | import java.awt.GridLayout; 6 | import java.awt.event.ActionEvent; 7 | import java.awt.event.ActionListener; 8 | import java.util.Arrays; 9 | 10 | import javax.swing.*; 11 | 12 | import CommonClass.Information; 13 | import DesktopServerProcess.Server; 14 | import DesktopServerProcess.ServerThread; 15 | 16 | 17 | public class taskViewFrame { 18 | 19 | private JFrame main; 20 | private JPanel list; 21 | private JScrollPane listRoll; 22 | private static taskViewFrame instance; 23 | private Object source; 24 | private String ip; 25 | private taskViewFrame() { 26 | main = new JFrame("进程监控"); 27 | list = new JPanel(new GridLayout(0, 1)); 28 | listRoll = new JScrollPane(list); 29 | Container c = main.getContentPane(); 30 | 31 | c.add(listRoll); 32 | 33 | main.setSize(new Dimension(600, 800)); 34 | } 35 | public void setIp(String Ip) { 36 | ip = Ip; 37 | } 38 | public static taskViewFrame getFrame() { 39 | if(instance == null) instance = new taskViewFrame(); 40 | return instance; 41 | } 42 | 43 | private void add(String value) { 44 | list.add(new ProcessView(value)); 45 | } 46 | 47 | public void view(Information task) { 48 | main.setTitle("进程监控 : " + ip); 49 | list.removeAll(); 50 | list.add(new ProcessView()); 51 | String content = task.getContent(); 52 | String[] lines = content.split("\r\n"); 53 | Arrays.sort(lines); 54 | for(String line:lines) { 55 | add(line); 56 | } 57 | main.setVisible(true); 58 | } 59 | 60 | public Object getSource() { 61 | return source; 62 | } 63 | public void setSource(Object source) { 64 | this.source = source; 65 | } 66 | 67 | public class ProcessView extends JPanel { 68 | 69 | /** 70 | * 71 | */ 72 | private static final long serialVersionUID = 1L; 73 | private JLabel name; 74 | private JLabel memory; 75 | private JButton over; 76 | public ProcessView(String value) { 77 | // TODO Auto-generated constructor stub 78 | super(new GridLayout(1, 3)); 79 | String[] a = value.split("#"); 80 | name = new JLabel(a[0]); 81 | memory = new JLabel(a[1]); 82 | over = new JButton("结束"); 83 | over.addActionListener(new Action()); 84 | 85 | add(name); 86 | add(memory); 87 | add(over); 88 | } 89 | 90 | public ProcessView() { 91 | // TODO Auto-generated constructor stub 92 | //jp = new JPanel(new FlowLayout()); 93 | super(new GridLayout(1, 3)); 94 | name = new JLabel("进程名称"); 95 | memory = new JLabel("内存占用"); 96 | JButton refresh = new JButton("刷新"); 97 | refresh.addActionListener(new ActionListener() { 98 | 99 | @Override 100 | public void actionPerformed(ActionEvent e) { 101 | // TODO Auto-generated method stub 102 | ServerThread.getServerThread(ip).sendMessage(new Information("tasklist", "Server", "tasklist", ip)); 103 | } 104 | }); 105 | //JLabel over = new JLabel("结束进程"); 106 | //over.addActionListener(new Action()); 107 | 108 | add(name); 109 | add(memory); 110 | add(refresh); 111 | } 112 | public class Action implements ActionListener { 113 | 114 | @Override 115 | public void actionPerformed(ActionEvent e) { 116 | // TODO Auto-generated method stub 117 | ServerThread.getServerThread(ip).sendMessage(new Information("cmd", Server.getName(), "taskkill /F /IM " + name.getText() + " /T", ip)); 118 | try { 119 | Thread.sleep(500); 120 | } catch (InterruptedException e1) { 121 | // TODO Auto-generated catch block 122 | e1.printStackTrace(); 123 | } 124 | ServerThread.getServerThread(ip).sendMessage(new Information("tasklist", "Server", "tasklist", ip)); 125 | } 126 | 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/DesktopServerProcess/Server.java: -------------------------------------------------------------------------------- 1 | package DesktopServerProcess; 2 | //教师端接收文件,以及教师端程序main函数 3 | import java.io.*; 4 | import java.net.InetAddress; 5 | import java.net.ServerSocket; 6 | import java.net.Socket; 7 | 8 | import CommonClass.DesktopRemoteType; 9 | import DesktopServerUI.ServerMainFrame; 10 | 11 | 12 | public class Server { 13 | private final String SelfAddress; 14 | private final String HostName; 15 | private int port; 16 | private ServerSocket server; 17 | private ServerSocket fileserver; 18 | private static String name = "Server"; 19 | 20 | public Server(DesktopRemoteType type) throws IOException { 21 | InetAddress ia = null; 22 | try { 23 | ia = InetAddress.getLocalHost(); 24 | } catch (Exception e) { 25 | // TODO Auto-generated catch block 26 | e.printStackTrace(); 27 | } 28 | this.HostName = ia.getHostName(); 29 | this.SelfAddress = ia.getHostAddress(); 30 | port = type.getPort(); 31 | server = new ServerSocket(port, 30); 32 | fileserver = new ServerSocket(DesktopRemoteType.ServerFile.getPort(), 33 | 30); 34 | new Thread(new openSocket()).start(); 35 | new Thread(new Runnable() { 36 | 37 | @Override 38 | public synchronized void run() { 39 | // TODO Auto-generated method stub 40 | Socket client; 41 | DataInputStream inputStream = null; 42 | DataInputStream getMessageStream = null; 43 | while (true) { 44 | try { 45 | client = fileserver.accept(); 46 | getMessageStream = new DataInputStream(new BufferedInputStream(client.getInputStream())); 47 | 48 | inputStream = getMessageStream; 49 | String savePath = "D:\\receive\\"; 50 | File path = new File(savePath); 51 | path.mkdir(); 52 | int bufferSize = 8192; 53 | byte[] buf = new byte[bufferSize]; 54 | int passedlen = 0; 55 | long len = 0; 56 | savePath += client.getInetAddress().getHostAddress(); 57 | String filename = inputStream.readUTF(); 58 | savePath += " - " + filename; 59 | 60 | DataOutputStream fileOut = new DataOutputStream(new BufferedOutputStream(new BufferedOutputStream(new FileOutputStream(savePath)))); 61 | len = inputStream.readLong(); 62 | System.out.println("文件的长度为:" + len + "\n"); 63 | System.out.println("开始接收文件!" + "\n"); 64 | while (true) { 65 | int read = 0; 66 | if (inputStream != null) { 67 | read = inputStream.read(buf); 68 | } 69 | passedlen += read; 70 | if (read <= 0) { 71 | break; 72 | } 73 | // 下面进度条本为图形界面的prograssBar做的,这里如果是打文件,可能会重复打印出一些相同的百分比 74 | System.out.println("文件接收了" + (passedlen * 100 / len) + "%\n"); 75 | fileOut.write(buf, 0, read); 76 | } 77 | System.out.println("接收完成,文件存为" + savePath + "\n"); 78 | ServerMainFrame.getFrame().addSession("收到文件 \"" + filename + "\""); 79 | fileOut.close(); 80 | inputStream.close(); 81 | getMessageStream.close(); 82 | 83 | } catch (FileNotFoundException e) { 84 | // TODO Auto-generated catch block 85 | e.printStackTrace(); 86 | } catch (IOException e) { 87 | // TODO Auto-generated catch block 88 | e.printStackTrace(); 89 | } 90 | } 91 | } 92 | }).start(); 93 | } 94 | 95 | /** 96 | * @return 打开Socket通信 97 | * @throws IOException 98 | */ 99 | public class openSocket implements Runnable { 100 | 101 | @Override 102 | public void run() { 103 | while (true) { 104 | ServerThread conn; 105 | // Socket ss; 106 | try { 107 | conn = new ServerThread(server.accept()); 108 | ServerThread.addUserList(conn.getSocket().getInetAddress() 109 | .getHostAddress(), conn); 110 | conn.listen(true); 111 | // ss = fileserver.accept(); 112 | // ServerThread.getServerThread(ss.getInetAddress()).setFileSocket(ss); 113 | // System.out.println("Server : " + conn); 114 | } catch (IOException e) { 115 | // TODO Auto-generated catch block 116 | e.printStackTrace(); 117 | } 118 | 119 | } 120 | } 121 | } 122 | 123 | public String getHostName() { 124 | return HostName; 125 | } 126 | 127 | public String getSelfAddress() { 128 | return SelfAddress; 129 | } 130 | 131 | public static void main(String[] args) throws Exception { 132 | ServerMainFrame.getFrame(); 133 | new Server(DesktopRemoteType.OtherType); 134 | ServerShotHandler.getThread().start(); 135 | } 136 | 137 | public static String getName() { 138 | return name; 139 | } 140 | 141 | public static void setName(String name) { 142 | Server.name = name; 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/DesktopServerUI/FileFrame.java: -------------------------------------------------------------------------------- 1 | package DesktopServerUI; 2 | //传文件的窗口(教师给学生) 3 | import java.awt.Container; 4 | import java.awt.FlowLayout; 5 | import java.awt.event.ActionEvent; 6 | import java.awt.event.ActionListener; 7 | import java.io.BufferedInputStream; 8 | import java.io.DataInputStream; 9 | import java.io.DataOutputStream; 10 | import java.io.File; 11 | import java.io.FileInputStream; 12 | import java.io.FileNotFoundException; 13 | import java.io.IOException; 14 | import java.net.Socket; 15 | import java.net.UnknownHostException; 16 | import java.util.ArrayList; 17 | 18 | import javax.swing.*; 19 | 20 | import CommonClass.DesktopRemoteType; 21 | 22 | 23 | 24 | 25 | public class FileFrame { 26 | private static ArrayList ips; 27 | private static FileFrame fileFrame; 28 | private JFrame frm; 29 | private JButton open; 30 | private JButton confirm; 31 | private JLabel filePathTF; 32 | private JPanel row1, row2; 33 | private File f; 34 | private WindowsFileChooser fc; 35 | 36 | private int flag; 37 | public static FileFrame getFrame() { 38 | if(fileFrame == null) 39 | fileFrame = new FileFrame(); 40 | return fileFrame; 41 | } 42 | private FileFrame() { 43 | frm = new JFrame("发送文件"); 44 | open = new JButton("选择文件"); 45 | confirm = new JButton("确定"); 46 | row1 = new JPanel(); 47 | row2 = new JPanel(); 48 | fc = new WindowsFileChooser(); 49 | filePathTF = new JLabel("请选择文件"); 50 | 51 | frm.setSize(80, 50); 52 | Container c = frm.getContentPane(); 53 | c.setLayout(new FlowLayout(FlowLayout.CENTER)); 54 | 55 | c.add(row2); 56 | c.add(row1); 57 | row2.add(filePathTF); 58 | row1.add(open); 59 | row1.add(confirm); 60 | 61 | open.addActionListener(new FileAction()); 62 | confirm.addActionListener(new FileAction()); 63 | 64 | 65 | frm.setSize(300, 300); 66 | //frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 67 | } 68 | public static void setIps(ArrayList ip) { 69 | ips = ip; 70 | } 71 | public void setVis(boolean ok) { 72 | frm.setVisible(ok); 73 | } 74 | class FileAction implements ActionListener { 75 | @Override 76 | public void actionPerformed(ActionEvent e) { 77 | // TODO Auto-generated method stub 78 | if(e.getSource() == open) { 79 | openFile(); 80 | } else if(e.getSource() == confirm) { 81 | confirmFile(); 82 | } 83 | } 84 | 85 | } 86 | 87 | private void openFile() { 88 | fc.setDialogTitle("Open File"); 89 | flag = fc.showOpenDialog(frm); 90 | if(flag == JFileChooser.APPROVE_OPTION) { 91 | f = fc.getSelectedFile(); 92 | filePathTF.setText(f.getPath()); 93 | } 94 | } 95 | 96 | private void confirmFile() { 97 | setVis(false); 98 | if(f.equals(null)) return; 99 | for(String ip:ips){ 100 | new Thread(new RunSend(ip, f.getPath())).start(); 101 | } 102 | } 103 | public String getFileName() { 104 | return filePathTF.getText(); 105 | } 106 | public class RunSend implements Runnable { 107 | String ip; 108 | private DataInputStream fis; 109 | public RunSend(String IP, String path) { 110 | ip = IP; 111 | try { 112 | fis = new DataInputStream(new BufferedInputStream(new FileInputStream(path))); 113 | } catch (FileNotFoundException e) { 114 | // TODO Auto-generated catch block 115 | e.printStackTrace(); 116 | } 117 | } 118 | @Override 119 | public void run() { 120 | // TODO Auto-generated method stub 121 | try { 122 | Socket ss = new Socket(ip, DesktopRemoteType.ClientFile.getPort()); 123 | DataOutputStream ps = new DataOutputStream(ss.getOutputStream()); 124 | ps.writeUTF(f.getName()); 125 | ps.flush(); 126 | ps.writeLong((long) f.length()); 127 | ps.flush(); 128 | 129 | int bufferSize = 8192; 130 | byte[] buf = new byte[bufferSize]; 131 | 132 | while (true) { 133 | int read = 0; 134 | if (fis != null) { 135 | read = fis.read(buf); 136 | } 137 | 138 | if (read <= 0) { 139 | break; 140 | } 141 | ps.write(buf, 0, read); 142 | } 143 | System.out.println("文件发送完成"); 144 | ps.flush(); 145 | ps.close(); 146 | 147 | } catch (UnknownHostException e) { 148 | // TODO Auto-generated catch block 149 | e.printStackTrace(); 150 | } catch (IOException e) { 151 | // TODO Auto-generated catch block 152 | e.printStackTrace(); 153 | } 154 | } 155 | 156 | } 157 | public class WindowsFileChooser extends JFileChooser { 158 | 159 | /** 160 | * 161 | */ 162 | private static final long serialVersionUID = -5196282709462572561L; 163 | 164 | public WindowsFileChooser() { 165 | String lookAndFeel = UIManager.getSystemLookAndFeelClassName(); 166 | try { 167 | UIManager.setLookAndFeel(lookAndFeel); 168 | } catch (ClassNotFoundException e) { 169 | // TODO Auto-generated catch block 170 | e.printStackTrace(); 171 | } catch (InstantiationException e) { 172 | // TODO Auto-generated catch block 173 | e.printStackTrace(); 174 | } catch (IllegalAccessException e) { 175 | // TODO Auto-generated catch block 176 | e.printStackTrace(); 177 | } catch (UnsupportedLookAndFeelException e) { 178 | // TODO Auto-generated catch block 179 | e.printStackTrace(); 180 | } 181 | 182 | SwingUtilities.updateComponentTreeUI(this); 183 | } 184 | } 185 | } -------------------------------------------------------------------------------- /src/DesktopClientProcess/Client.java: -------------------------------------------------------------------------------- 1 | package DesktopClientProcess; 2 | //学生端的main函数,输入ip连接,以及接收文件 3 | import java.io.*; 4 | import java.net.*; 5 | 6 | import CommonClass.DesktopRemoteType; 7 | import CommonClass.Information; 8 | import CommonClass.XMLUtil; 9 | 10 | 11 | /** 12 | * @author Administrator 13 | * 学生端类 14 | */ 15 | public class Client { 16 | private final String SelfAddress; 17 | private final String HostName; 18 | private static String ServerAddress; 19 | private int port; 20 | private Socket socket; 21 | public Socket getSocket() { 22 | return socket; 23 | } 24 | 25 | private ServerSocket filesocket; 26 | 27 | private ClientSocketHandler handler; 28 | 29 | public Client(DesktopRemoteType type) throws IOException { 30 | this.port = type.getPort(); 31 | InetAddress ia = null; 32 | try { 33 | ia = InetAddress.getLocalHost(); 34 | } catch (Exception e) { 35 | // TODO Auto-generated catch block 36 | e.printStackTrace(); 37 | } 38 | this.HostName = ia.getHostName(); 39 | this.SelfAddress = ia.getHostAddress(); 40 | openSocket(); 41 | handler = new ClientSocketHandler(this); 42 | handler.listen(true); 43 | new ClientShot(); 44 | filesocket = new ServerSocket(DesktopRemoteType.ClientFile.getPort()); 45 | new FileReceive().start(); 46 | System.out.println("shot start..."); 47 | } 48 | 49 | /** 50 | * @return 打开Socket通信 51 | */ 52 | public void openSocket() { 53 | boolean ok = false; 54 | String ip = null; 55 | if (!XMLUtil.exist()) { 56 | ip = javax.swing.JOptionPane.showInputDialog(null, " 输入服务器地址"); 57 | XMLUtil.createXML(ip); 58 | } 59 | while (!ok) { 60 | try { 61 | Client.ServerAddress = XMLUtil.getBean("server"); 62 | socket = new Socket(Client.ServerAddress, this.port); 63 | socket.setKeepAlive(true); 64 | socket.setTcpNoDelay(true); 65 | ok = true; 66 | } catch (UnknownHostException e) { 67 | ip = javax.swing.JOptionPane.showInputDialog(null, 68 | "服务器地址有误,请重新输入服务器地址"); 69 | XMLUtil.createXML(ip); 70 | } catch (ConnectException ex) { 71 | ip = javax.swing.JOptionPane.showInputDialog(null, 72 | "连接服务器超时,请重新输入服务器地址"); 73 | XMLUtil.createXML(ip); 74 | } catch (Exception e) { 75 | ip = javax.swing.JOptionPane.showInputDialog(null, 76 | "连接服务器失败,请重新输入服务器地址"); 77 | XMLUtil.createXML(ip); 78 | } 79 | } 80 | } 81 | 82 | /** 83 | * @return 关闭Socket通信 84 | */ 85 | public boolean closeSocket() { 86 | try { 87 | this.socket.close(); 88 | // this.filesocket.close(); 89 | } catch (IOException e) { 90 | // TODO Auto-generated catch block 91 | e.printStackTrace(); 92 | return false; 93 | } 94 | return true; 95 | } 96 | 97 | /** 98 | * @return 向服务端发送消息 99 | */ 100 | public void send(Information info) { 101 | handler.sendMessage(info.toString()); 102 | } 103 | 104 | /** 105 | * @return 接收服务端的消息 106 | */ 107 | public Information receive() { 108 | return null; 109 | } 110 | 111 | public class FileReceive extends Thread { 112 | /** 113 | * @return 接收来自服务端的文件 114 | */ 115 | public void run() { 116 | Socket client; 117 | DataInputStream inputStream = null; 118 | DataInputStream getMessageStream = null; 119 | while (true) { 120 | try { 121 | client = filesocket.accept(); 122 | getMessageStream = new DataInputStream( 123 | new BufferedInputStream(client.getInputStream())); 124 | } catch (IOException e1) { 125 | // TODO Auto-generated catch block 126 | e1.printStackTrace(); 127 | } 128 | inputStream = getMessageStream; 129 | String savePath = "D:\\receive\\"; 130 | File path = new File(savePath); 131 | path.mkdir(); 132 | int bufferSize = 8192; 133 | byte[] buf = new byte[bufferSize]; 134 | int passedlen = 0; 135 | long len = 0; 136 | try { 137 | savePath += inputStream.readUTF(); 138 | DataOutputStream fileOut = new DataOutputStream( 139 | new BufferedOutputStream(new BufferedOutputStream( 140 | new FileOutputStream(savePath)))); 141 | len = inputStream.readLong(); 142 | System.out.println("文件的长度为:" + len + "\n"); 143 | System.out.println("开始接收文件!" + "\n"); 144 | while (true) { 145 | int read = 0; 146 | if (inputStream != null) { 147 | read = inputStream.read(buf); 148 | } 149 | passedlen += read; 150 | if (read <= 0) { 151 | break; 152 | } 153 | // 下面进度条本为图形界面的prograssBar做的,这里如果是打文件,可能会重复打印出一些相同的百分比 154 | System.out.println("文件接收了" + (passedlen * 100 / len) 155 | + "%\n"); 156 | fileOut.write(buf, 0, read); 157 | } 158 | System.out.println("接收完成,文件存为" + savePath + "\n"); 159 | fileOut.close(); 160 | inputStream.close(); 161 | getMessageStream.close(); 162 | 163 | } catch (FileNotFoundException e) { 164 | // TODO Auto-generated catch block 165 | e.printStackTrace(); 166 | } catch (IOException e) { 167 | // TODO Auto-generated catch block 168 | e.printStackTrace(); 169 | } 170 | } 171 | } 172 | } 173 | 174 | public String toString() { 175 | return HostName + ":" + SelfAddress; 176 | } 177 | 178 | public static String getServerAddress() { 179 | return ServerAddress; 180 | } 181 | 182 | public void setServerAddress(String serverAddress) { 183 | ServerAddress = serverAddress; 184 | } 185 | 186 | public String getSelfAddress() { 187 | return SelfAddress; 188 | } 189 | 190 | public int getPort() { 191 | return port; 192 | } 193 | 194 | public static void main(String args[]) throws IOException { 195 | // String ip = javax.swing.JOptionPane.showInputDialog(null, 196 | // "服务器地址有误,请重新输入服务器地址"); 197 | new Client(DesktopRemoteType.OtherType); 198 | } 199 | 200 | } -------------------------------------------------------------------------------- /src/DesktopClientUI/ClientDialogUI.java: -------------------------------------------------------------------------------- 1 | package DesktopClientUI; 2 | //学生端界面布局,发文件 3 | import java.awt.*; 4 | import java.awt.event.ActionEvent; 5 | import java.awt.event.ActionListener; 6 | import java.io.BufferedInputStream; 7 | import java.io.DataInputStream; 8 | import java.io.DataOutputStream; 9 | import java.io.File; 10 | import java.io.FileInputStream; 11 | import java.io.IOException; 12 | import java.net.Socket; 13 | 14 | import javax.swing.*; 15 | import javax.swing.plaf.basic.BasicButtonUI; 16 | 17 | 18 | import CommonClass.DesktopRemoteType; 19 | import CommonClass.Information; 20 | import DesktopClientProcess.Client; 21 | 22 | public class ClientDialogUI { 23 | private JFrame chat; 24 | private JButton send, raisehand; 25 | private JPanel row1, row2, row3; 26 | private JPanel row2_1; 27 | private JComboBox object; 28 | private JButton sendfile; 29 | private JScrollPane sessionRoll, msgRoll; 30 | private JTextArea session; 31 | private JTextArea msg; 32 | private Client client; 33 | 34 | private JFileChooser fc; 35 | 36 | public Socket getSocket() { 37 | return client.getSocket(); 38 | } 39 | 40 | public String getInetAddress() { 41 | return client.getSelfAddress(); 42 | } 43 | 44 | public ClientDialogUI(Client c) { 45 | client = c; 46 | chat = new JFrame("聊天室"); 47 | send = new JButton("发送"); 48 | raisehand = new JButton("举手"); 49 | row1 = new JPanel(); 50 | row2 = new JPanel(new BorderLayout()); 51 | row3 = new JPanel(new GridLayout(1, 2)); 52 | row2_1 = new JPanel(new FlowLayout()); 53 | msg = new JTextArea(5, 25); 54 | msg.setTabSize(4); 55 | msg.setFont(new Font("宋体", Font.BOLD, 16)); 56 | msg.setLineWrap(true); 57 | msg.setWrapStyleWord(true); 58 | 59 | fc = new JFileChooser(); 60 | 61 | session = new JTextArea(20, 27); 62 | session.setLineWrap(true); 63 | session.setWrapStyleWord(true); 64 | session.setFont(new Font("宋体", Font.BOLD, 16)); 65 | session.append("欢迎来到聊天室\n"); 66 | session.setEditable(false); 67 | sessionRoll = new JScrollPane(session); 68 | msgRoll = new JScrollPane(msg); 69 | object = new JComboBox(); 70 | object.addItem("至全体"); 71 | object.addItem("至老师"); 72 | object.setPreferredSize(new Dimension(115, 20)); 73 | Image image = (new ImageIcon(this.getClass().getResource("/image/tranFile.png"))).getImage(); 74 | Image smallImage = image.getScaledInstance(20, 20, Image.SCALE_FAST); 75 | sendfile = new JButton("交作业", new ImageIcon(smallImage)); 76 | sendfile.setPreferredSize(new Dimension(115, 20)); 77 | sendfile.setContentAreaFilled(false); 78 | sendfile.setUI(new BasicButtonUI()); 79 | sendfile.setMargin(new Insets(0, 0, 0, 0)); 80 | 81 | sendfile.addActionListener(new ActionListener() { 82 | 83 | @Override 84 | public void actionPerformed(ActionEvent e) { 85 | // TODO Auto-generated method stub 86 | if (fc.showOpenDialog(chat) == JFileChooser.APPROVE_OPTION) { 87 | new Thread(new Runnable() { 88 | 89 | @Override 90 | public void run() { 91 | // TODO Auto-generated method stub 92 | File file = fc.getSelectedFile(); 93 | try { 94 | Socket filesocket = new Socket(Client 95 | .getServerAddress(), 96 | DesktopRemoteType.ServerFile.getPort()); 97 | DataInputStream fis = new DataInputStream( 98 | new BufferedInputStream( 99 | new FileInputStream(file 100 | .getAbsolutePath()))); 101 | DataOutputStream ps = new DataOutputStream( 102 | filesocket.getOutputStream()); 103 | ps.writeUTF(file.getName()); 104 | ps.flush(); 105 | ps.writeLong((long) file.length()); 106 | ps.flush(); 107 | 108 | int bufferSize = 8192; 109 | byte[] buf = new byte[bufferSize]; 110 | 111 | while (true) { 112 | int read = 0; 113 | if (fis != null) { 114 | read = fis.read(buf); 115 | } 116 | 117 | if (read <= 0) { 118 | break; 119 | } 120 | ps.write(buf, 0, read); 121 | } 122 | System.out.println("文件发送完成"); 123 | addSession("文件\"" + file.getName() + "\"发送完成"); 124 | ps.flush(); 125 | ps.close(); 126 | fis.close(); 127 | } catch (IOException e1) { 128 | // TODO Auto-generated catch block 129 | e1.printStackTrace(); 130 | } 131 | } 132 | 133 | }).start(); 134 | } 135 | } 136 | }); 137 | row2_1.add(object); 138 | row2_1.add(sendfile); 139 | row2_1.setAlignmentX(0); 140 | row2_1.setPreferredSize(new Dimension(0, 25)); 141 | chat.setSize(250, 600); 142 | Container con = chat.getContentPane(); 143 | con.setLayout(new BorderLayout()); 144 | row1.add(sessionRoll); 145 | // row2.setPreferredSize(new Dimension(250, 90)); 146 | row2.add(row2_1, BorderLayout.NORTH); 147 | row2.add(msgRoll, BorderLayout.CENTER); 148 | row3.add(raisehand); 149 | row3.add(send); 150 | con.add(row1, BorderLayout.NORTH); 151 | con.add(row2, BorderLayout.CENTER); 152 | con.add(row3, BorderLayout.SOUTH); 153 | 154 | raisehand.addActionListener(new Action()); 155 | send.addActionListener(new Action()); 156 | 157 | chat.setResizable(false); 158 | chat.setLocation(1050, 200); 159 | chat.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 160 | 161 | chat.setVisible(true); 162 | 163 | // setDesktop(); 164 | } 165 | 166 | public void addSession(String value) { 167 | session.append(value + "\r\n"); 168 | JScrollBar jsb = sessionRoll.getVerticalScrollBar(); 169 | jsb.setValue(jsb.getMaximum() + 1); 170 | } 171 | 172 | public class Action implements ActionListener { 173 | 174 | @Override 175 | public void actionPerformed(ActionEvent e) { 176 | // TODO Auto-generated method stub 177 | if (e.getSource() == send) { 178 | if (msg.getText().length() < 1) return; 179 | if(object.getSelectedItem().equals("至全体")) { 180 | addSession("[Me to all]" + msg.getText()); 181 | client.send(new Information("session",client.getSelfAddress(), msg.getText(),"all")); 182 | } else { 183 | addSession("[Me to Server]" + msg.getText()); 184 | client.send(new Information("session",client.getSelfAddress(), msg.getText(),"server")); 185 | } 186 | msg.setText(null); 187 | } else if (e.getSource() == raisehand) { 188 | addSession("[Me]我举了手"); 189 | client.send(Information.createRaiseHand(client.getSelfAddress())); 190 | } 191 | } 192 | } 193 | 194 | } 195 | -------------------------------------------------------------------------------- /src/DesktopServerProcess/ServerShotHandler.java: -------------------------------------------------------------------------------- 1 | package DesktopServerProcess; 2 | //教师端屏幕广播,监视学生端屏幕 3 | import java.awt.*; 4 | import java.awt.image.BufferedImage; 5 | import java.io.IOException; 6 | import java.net.*; 7 | import java.util.HashMap; 8 | import java.util.Iterator; 9 | import java.util.Map; 10 | import java.util.Map.Entry; 11 | import java.util.zip.*; 12 | 13 | import javax.imageio.ImageIO; 14 | import javax.swing.*; 15 | 16 | import com.sun.image.codec.jpeg.JPEGCodec; 17 | import commonUI.watchFrame; 18 | 19 | 20 | import CommonClass.DesktopRemoteType; 21 | import CommonClass.Information; 22 | import DesktopServerUI.PCPanel; 23 | import DesktopServerUI.ServerMainFrame; 24 | 25 | public class ServerShotHandler extends Thread{ 26 | private static Map UserList = new HashMap(); 27 | private Broadcast broadcast; 28 | private Thread last; 29 | private static ServerShotHandler servershot; 30 | public static ServerShotHandler getThread() { 31 | if(servershot == null) 32 | servershot = new ServerShotHandler(); 33 | return servershot; 34 | } 35 | private ServerShotHandler() { 36 | super(); 37 | Toolkit.getDefaultToolkit().getScreenSize(); 38 | broadcast = new Broadcast(); 39 | Screen p = new Screen(); 40 | new Thread(p).start(); 41 | } 42 | 43 | public static void main(String[] args) { 44 | new ServerShotHandler(); 45 | } 46 | 47 | public static int getTotal() { 48 | return UserList.size(); 49 | } 50 | 51 | public static PCPanel get(String string) { 52 | return UserList.get(string); 53 | } 54 | 55 | public void openBroadcast() { 56 | if(last != null) { 57 | closeBroadcast(); 58 | } 59 | last = new Thread(broadcast); 60 | last.start(); 61 | } 62 | public void closeBroadcast() { 63 | last.interrupt(); 64 | } 65 | class Broadcast implements Runnable { 66 | private Dimension screenSize; 67 | private Rectangle rectangle; 68 | private Robot robot; 69 | public Broadcast() { 70 | screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 71 | rectangle = new Rectangle(screenSize);// 可以指定捕获屏幕区域 72 | try { 73 | robot = new Robot(); 74 | } catch (Exception e) { 75 | e.printStackTrace(); 76 | System.out.println(e); 77 | } 78 | } 79 | 80 | public synchronized void run() { 81 | Socket socket = null; 82 | try { 83 | while (true) { 84 | BufferedImage image = robot.createScreenCapture(rectangle);// 捕获制定屏幕矩形区域 85 | Iterator> iter = ServerThread 86 | .getUser(); 87 | while (iter.hasNext()) { 88 | Map.Entry val = iter.next(); 89 | socket = new Socket(val.getKey(),DesktopRemoteType.ClientShot.getPort()); 90 | new Thread(new Send(socket, image)).start(); 91 | } 92 | Thread.sleep(500);// 每秒2帧 93 | } 94 | } catch (Exception e) { 95 | e.printStackTrace(); 96 | } finally { 97 | Iterator> iter = ServerThread 98 | .getUser(); 99 | while (iter.hasNext()) { 100 | Map.Entry val = iter.next(); 101 | val.getValue().sendMessage(new Information("boardcastclosed", "Server", "boardcastclosed", "all")); 102 | } 103 | } 104 | 105 | } 106 | 107 | class Send implements Runnable { 108 | ZipOutputStream os = null; 109 | Socket socket; 110 | BufferedImage image; 111 | public Send(Socket s, BufferedImage i) { 112 | socket = s; 113 | image = i; 114 | } 115 | @Override 116 | public void run() { 117 | // TODO Auto-generated method stub 118 | ZipOutputStream os = null; 119 | try { 120 | os = new ZipOutputStream(socket.getOutputStream()); 121 | os.setLevel(9); 122 | os.putNextEntry(new ZipEntry("test.jpg")); 123 | JPEGCodec.createJPEGEncoder(os).encode(image);// 图像编码成JPEG 124 | os.close(); 125 | } catch (IOException e) { 126 | // TODO Auto-generated catch block 127 | e.printStackTrace(); 128 | } finally { 129 | if (os != null) { 130 | try { 131 | os.close(); 132 | } catch (Exception ioe) { 133 | } 134 | } 135 | if (socket != null) { 136 | 137 | try { 138 | socket.close(); 139 | } catch (IOException e) { 140 | } 141 | } 142 | } 143 | } 144 | 145 | } 146 | 147 | } 148 | class Screen extends JPanel implements Runnable { 149 | 150 | private static final long serialVersionUID = 1L; 151 | private Image cimage; 152 | 153 | public synchronized void run() { 154 | ServerSocket ss = null; 155 | //int i = 0; 156 | try { 157 | ss = new ServerSocket(DesktopRemoteType.ServerShot.getPort()); 158 | while (true) { 159 | //System.out.println(i++); 160 | Socket s = null; 161 | try { 162 | s = ss.accept(); 163 | if(!UserList.containsKey(s.getInetAddress().getHostAddress())) { 164 | PCPanel jb = ServerMainFrame.addBtn(); 165 | jb.setClient(s); 166 | UserList.put(s.getInetAddress().getHostAddress(), jb); 167 | } 168 | PCPanel jb = UserList.get(s.getInetAddress().getHostAddress()); 169 | if(!jb.isVisible()) jb.setVisible(true); 170 | //jb.setVisible(true); 171 | ZipInputStream zis = new ZipInputStream(s 172 | .getInputStream()); 173 | zis.getNextEntry(); 174 | cimage = ImageIO.read(zis);// 把ZIP流转换为图片 175 | if(watchFrame.getFrame().isVis()) { 176 | if(s.getInetAddress().getHostAddress().equals(watchFrame.getFrame().getIp())) { 177 | int width = watchFrame.getFrame().getWidth(); 178 | int height = watchFrame.getFrame().getHeight(); 179 | cimage = cimage.getScaledInstance(width, height, Image.SCALE_FAST); 180 | watchFrame.getFrame().paint(cimage); 181 | } 182 | } else { 183 | cimage = cimage.getScaledInstance(200,150,Image.SCALE_FAST); 184 | ImageIcon cim = new ImageIcon(cimage); 185 | jb.setIcon(cim); 186 | } 187 | 188 | 189 | //ImageIO.write((RenderedImage) cimage, "jpg", new File("D:\\records\\" + (new Date()).getTime() + ".jpg")); 190 | //repaint(); 191 | } catch (Exception e) { 192 | e.printStackTrace(); 193 | } finally { 194 | if (s != null) { 195 | try { 196 | s.close(); 197 | } catch (IOException e) { 198 | e.printStackTrace(); 199 | } 200 | } 201 | } 202 | } 203 | } catch (Exception e) { 204 | } finally { 205 | if (ss != null) { 206 | try { 207 | ss.close(); 208 | } catch (IOException e) { 209 | e.printStackTrace(); 210 | } 211 | } 212 | } 213 | } 214 | 215 | public Screen() { 216 | super(); 217 | this.setLayout(null); 218 | } 219 | 220 | } 221 | } -------------------------------------------------------------------------------- /src/DesktopClientProcess/ClientSocketHandler.java: -------------------------------------------------------------------------------- 1 | package DesktopClientProcess; 2 | 3 | //学生端处理教师端的事务 4 | import java.io.BufferedReader; 5 | import java.io.IOException; 6 | import java.io.InputStreamReader; 7 | import java.io.OutputStreamWriter; 8 | import java.io.PrintWriter; 9 | import java.net.Socket; 10 | import java.net.SocketException; 11 | import java.util.regex.Matcher; 12 | import java.util.regex.Pattern; 13 | 14 | import commonUI.watchFrame; 15 | 16 | import CommonClass.Information; 17 | import CommonClass.SocketStatusListener; 18 | import DesktopClientUI.ClientDialogUI; 19 | 20 | 21 | /** 22 | * @author Administrator 23 | * 24 | */ 25 | public class ClientSocketHandler implements SocketStatusListener { 26 | 27 | protected Socket socket = null; 28 | 29 | protected ReaderTask reader; 30 | 31 | protected WriterTask writer; 32 | 33 | protected ClientDialogUI dialog; 34 | 35 | public ClientSocketHandler(Client client) throws IOException { 36 | dialog = new ClientDialogUI(client); 37 | this.socket = client.getSocket(); 38 | this.socket.setTcpNoDelay(true); 39 | System.out.println(socket.getLocalSocketAddress()); 40 | reader = new ReaderTask(socket); 41 | writer = new WriterTask(socket); 42 | onSocketStatusChanged(socket, STATUS_OPEN, null); 43 | } 44 | 45 | /** 46 | * sendMessage:(这里用一句话描述这个方法的作用).
47 | * TODO(这里描述这个方法适用条件 – 可选).
48 | */ 49 | public void sendMessage(String msg) { 50 | writer.send(msg); 51 | } 52 | 53 | public void listen(boolean isListen) { 54 | reader.startListener(this); 55 | 56 | } 57 | 58 | public void shutDown() { 59 | 60 | if (!socket.isClosed() && socket.isConnected()) { 61 | try { 62 | writer.finish(); 63 | reader.finish(); 64 | socket.close(); 65 | } catch (IOException e) { 66 | e.printStackTrace(); 67 | onSocketStatusChanged(socket, STATUS_CLOSE, e); 68 | } finally { 69 | reader = null; 70 | writer = null; 71 | System.out.println("Socket连接已关闭!!"); 72 | System.exit(1); 73 | } 74 | } 75 | 76 | } 77 | 78 | @Override 79 | public void onSocketStatusChanged(Socket socket, int status, IOException e) { 80 | 81 | switch (status) { 82 | 83 | case SocketStatusListener.STATUS_CLOSE: 84 | case SocketStatusListener.STATUS_RESET: 85 | case SocketStatusListener.STATUS_PIP_BROKEN: 86 | shutDown(); 87 | break; 88 | 89 | default: 90 | break; 91 | } 92 | } 93 | 94 | /** 95 | * @author Administrator 96 | * 读操作进程 97 | */ 98 | public class ReaderTask extends Thread { 99 | 100 | private SocketStatusListener socketStatusListener; 101 | 102 | private BufferedReader bufferedReader; 103 | 104 | private Socket socket; 105 | 106 | private boolean listening; 107 | 108 | 109 | public ReaderTask(Socket socket) throws IOException { 110 | bufferedReader = new BufferedReader(new InputStreamReader( 111 | socket.getInputStream(), "UTF-8")); 112 | this.socket = socket; 113 | } 114 | 115 | /** 116 | * finish:(这里用一句话描述这个方法的作用).
117 | * TODO(这里描述这个方法适用条件 – 可选).
118 | * 119 | * @throws IOException 120 | * 121 | */ 122 | public void finish() throws IOException { 123 | listening = false; 124 | interrupt(); 125 | if (bufferedReader != null && socket != null) { 126 | if (socket.isInputShutdown()) { 127 | socket.shutdownInput(); 128 | } 129 | bufferedReader.close(); 130 | } 131 | } 132 | 133 | /* 134 | * (non-Javadoc) 135 | * 136 | * @see java.lang.Runnable#run() 137 | */ 138 | @Override 139 | public synchronized void run() { 140 | while (listening) { 141 | String readStr = null; 142 | try { 143 | while ((readStr = bufferedReader.readLine()) != null) { 144 | System.err.println("[Server]:"+readStr); 145 | Information reci = new Information(readStr); 146 | //System.out.println(reci.getContent()); 147 | if(reci.getType().equals("session")) { 148 | if(reci.getToAdd().equals("all")) 149 | dialog.addSession("[" + reci.getFromAdd() + " to " + reci.getToAdd() + "] 对话\r\n" + reci.getContent()); 150 | else 151 | dialog.addSession("[" + reci.getFromAdd() + " to Me] 对话\r\n" + reci.getContent()); 152 | } else if(reci.getType().equals("shutdown")) { 153 | Runtime.getRuntime().exec(reci.getContent()); 154 | } else if(reci.getType().equals("tasklist")) { 155 | Pattern pp = Pattern.compile("(\\b\\w+.exe)|((?<=[10]\\b)\\s+[0-9,]+(?= K))"); 156 | Process p = Runtime.getRuntime().exec(reci.getContent()); 157 | BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); 158 | String line = null; 159 | String contents = ""; 160 | while ((line = br.readLine()) != null) { 161 | Matcher res = pp.matcher(line); 162 | int cnt = 0; 163 | String buf = ""; 164 | while(res.find()) { 165 | System.out.println(res.group().trim()); 166 | if(cnt == 0) buf += res.group().trim() + "#"; 167 | else buf += res.group().trim() + " K"; 168 | cnt ++; 169 | } 170 | if(cnt == 2) contents += buf + "\r\n"; 171 | } 172 | writer.send(new Information("tasklist", dialog.getInetAddress(), contents, "Server").toString()); 173 | } else if(reci.getType().equals("cmd")) { 174 | Runtime.getRuntime().exec(reci.getContent()); 175 | } else if(reci.getType().equals("boardcastclosed")) { 176 | watchFrame.getFrame().setVisible(false); 177 | } 178 | } 179 | } catch (IOException e) { 180 | listening = false; 181 | if (socketStatusListener != null) { 182 | int status = parseSocketStatus(e); 183 | socketStatusListener.onSocketStatusChanged(socket, 184 | status, e); 185 | } 186 | e.printStackTrace(); 187 | return;// 终止线程继续运行,这里也可以使用continue 188 | } 189 | 190 | } 191 | } 192 | 193 | private int parseSocketStatus(IOException e) { 194 | if (SocketException.class.isInstance(e)) { 195 | String msg = e.getLocalizedMessage().trim(); 196 | if ("Connection reset".equalsIgnoreCase(msg)) { 197 | return SocketStatusListener.STATUS_RESET; 198 | } else if ("Socket is closed".equalsIgnoreCase(msg)) { 199 | return SocketStatusListener.STATUS_CLOSE; 200 | } else if ("Broken pipe".equalsIgnoreCase(msg)) { 201 | return SocketStatusListener.STATUS_PIP_BROKEN; 202 | } 203 | 204 | } 205 | return SocketStatusListener.STATUS_UNKOWN; 206 | } 207 | 208 | /** 209 | * listen:(这里用一句话描述这个方法的作用).
210 | * TODO(这里描述这个方法适用条件 – 可选).
211 | * 212 | */ 213 | public void startListener(SocketStatusListener ssl) { 214 | listening = true; 215 | this.socketStatusListener = ssl; 216 | start(); 217 | } 218 | 219 | } 220 | 221 | 222 | /** 223 | * @author Administrator 224 | * 写操作进程 225 | */ 226 | public class WriterTask extends Thread{ 227 | 228 | private PrintWriter bufferedWriter; 229 | 230 | private String msg = null; 231 | 232 | private Socket socket = null; 233 | 234 | public WriterTask(Socket socket) throws IOException { 235 | this.bufferedWriter = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8")); 236 | this.socket = socket; 237 | } 238 | 239 | /** 240 | * finishTask:(这里用一句话描述这个方法的作用).
241 | * TODO(这里描述这个方法适用条件 – 可选).
242 | * @throws IOException 243 | * 244 | */ 245 | public void finish() throws IOException { 246 | if(bufferedWriter!=null && socket!=null) 247 | { 248 | if(!socket.isOutputShutdown()) 249 | { 250 | socket.shutdownOutput(); 251 | } 252 | bufferedWriter.close(); 253 | } 254 | } 255 | 256 | /* (non-Javadoc) 257 | * @see java.lang.Runnable#run() 258 | */ 259 | @Override 260 | public synchronized void run() { 261 | bufferedWriter.println(msg); 262 | bufferedWriter.flush(); 263 | System.out.println("我发出了:"+msg); 264 | } 265 | 266 | public void send(String msg){ 267 | 268 | this.msg = msg; 269 | new Thread(this).start(); 270 | } 271 | 272 | } 273 | 274 | } -------------------------------------------------------------------------------- /src/DesktopServerProcess/ServerSocketHandler.java: -------------------------------------------------------------------------------- 1 | package DesktopServerProcess; 2 | //接收学生端举手,消息,在线人数改变,发文件给学生端 3 | import java.io.*; 4 | import java.net.Socket; 5 | import java.net.SocketException; 6 | import java.util.Iterator; 7 | import java.util.Map; 8 | import java.util.Map.Entry; 9 | 10 | 11 | import CommonClass.Information; 12 | import CommonClass.SocketStatusListener; 13 | import DesktopServerUI.ServerMainFrame; 14 | import DesktopServerUI.taskViewFrame; 15 | 16 | 17 | /** 18 | * @author Administrator 19 | * 20 | */ 21 | public class ServerSocketHandler implements SocketStatusListener { 22 | 23 | private static ServerMainFrame mainframe = ServerMainFrame.getFrame(); 24 | 25 | protected Socket filesocket = null; 26 | 27 | protected Socket socket = null; 28 | 29 | protected ReaderTask reader; 30 | 31 | protected WriterTask writer; 32 | 33 | public ServerSocketHandler(Socket socket) throws IOException { 34 | 35 | this.socket = socket; 36 | this.socket.setTcpNoDelay(true); 37 | reader = new ReaderTask(socket); 38 | writer = new WriterTask(socket); 39 | onSocketStatusChanged(socket, STATUS_OPEN, null); 40 | } 41 | 42 | public void setFileSocket(Socket socket) { 43 | filesocket = socket; 44 | } 45 | 46 | public void sendFile(String filename) { 47 | new SendFile(filename).start(); 48 | } 49 | /** 50 | * sendMessage:(这里用一句话描述这个方法的作用).
51 | * TODO(这里描述这个方法适用条件 – 可选).
52 | */ 53 | public void sendMessage(String msg) { 54 | writer.send(msg); 55 | } 56 | 57 | public void listen(boolean isListen) { 58 | reader.startListener(this); 59 | 60 | } 61 | 62 | public void shutDown() { 63 | 64 | if (!socket.isClosed() && socket.isConnected()) { 65 | try { 66 | writer.finish(); 67 | reader.finish(); 68 | socket.close(); 69 | } catch (IOException e) { 70 | e.printStackTrace(); 71 | onSocketStatusChanged(socket, STATUS_CLOSE, e); 72 | } finally { 73 | reader = null; 74 | writer = null; 75 | System.out.println("Socket连接已关闭!!"); 76 | } 77 | } 78 | 79 | } 80 | 81 | @Override 82 | public void onSocketStatusChanged(Socket socket, int status, IOException e) { 83 | 84 | switch (status) { 85 | 86 | case SocketStatusListener.STATUS_CLOSE: 87 | case SocketStatusListener.STATUS_RESET: 88 | case SocketStatusListener.STATUS_PIP_BROKEN: 89 | shutDown(); 90 | break; 91 | 92 | default: 93 | break; 94 | } 95 | } 96 | 97 | /** 98 | * @return 99 | * 向客户端发送文件 100 | */ 101 | private class SendFile extends Thread { 102 | 103 | private String filepath; 104 | public SendFile(String filepath) { 105 | this.filepath = filepath; 106 | } 107 | public void run() { 108 | File file = new File(filepath); 109 | try { 110 | DataInputStream fis = new DataInputStream(new BufferedInputStream(new FileInputStream(filepath))); 111 | DataOutputStream ps = new DataOutputStream(filesocket.getOutputStream()); 112 | ps.writeUTF(file.getName()); 113 | ps.flush(); 114 | ps.writeLong((long) file.length()); 115 | ps.flush(); 116 | 117 | int bufferSize = 8192; 118 | byte[] buf = new byte[bufferSize]; 119 | 120 | while (true) { 121 | int read = 0; 122 | if (fis != null) { 123 | read = fis.read(buf); 124 | } 125 | 126 | if (read <= 0) { 127 | break; 128 | } 129 | ps.write(buf, 0, read); 130 | } 131 | System.out.println("文件发送完成"); 132 | ps.flush(); 133 | ps.close(); 134 | fis.close(); 135 | } catch (IOException e) { 136 | // TODO Auto-generated catch block 137 | e.printStackTrace(); 138 | } 139 | } 140 | } 141 | 142 | /** 143 | * @author Administrator 144 | * 读操作进程 145 | */ 146 | public class ReaderTask extends Thread { 147 | 148 | private SocketStatusListener socketStatusListener; 149 | 150 | private BufferedReader bufferedReader; 151 | 152 | private Socket socket; 153 | 154 | private boolean listening; 155 | 156 | 157 | public ReaderTask(Socket socket) throws IOException { 158 | bufferedReader = new BufferedReader(new InputStreamReader( 159 | socket.getInputStream(), "UTF-8")); 160 | this.socket = socket; 161 | } 162 | 163 | /** 164 | * finish:(这里用一句话描述这个方法的作用).
165 | * TODO(这里描述这个方法适用条件 – 可选).
166 | * 167 | * @throws IOException 168 | * 169 | */ 170 | public void finish() throws IOException { 171 | listening = false; 172 | interrupt(); 173 | if (bufferedReader != null && socket != null) { 174 | if (socket.isInputShutdown()) { 175 | socket.shutdownInput(); 176 | } 177 | bufferedReader.close(); 178 | } 179 | } 180 | 181 | /* 182 | * (non-Javadoc) 183 | * 184 | * @see java.lang.Runnable#run() 185 | */ 186 | @Override 187 | public synchronized void run() { 188 | System.out.println(1); 189 | while (listening) { 190 | String readStr = null; 191 | try { 192 | mainframe.addSession("[" + socket.getInetAddress().getHostAddress() + "] 已上线"); 193 | mainframe.setOnlineMember("当前在线人数为:" + ServerThread.getUserList()); 194 | while ((readStr = bufferedReader.readLine()) != null) { 195 | Information reci = new Information(readStr); 196 | 197 | if(reci.getType().equals("session")) { 198 | if(!reci.getToAdd().equals("all")) { 199 | mainframe.addSession("[" + reci.getFromAdd() + " to Me] 对话 \n" + reci.getContent()); 200 | continue; 201 | } 202 | mainframe.addSession("[" + reci.getFromAdd() + " to all] 对话 \n" + reci.getContent()); 203 | Iterator> iter = ServerThread.getUser(); 204 | while(iter.hasNext()) { 205 | Map.Entry val = iter.next(); 206 | if(!val.getKey().equals(socket.getInetAddress().getHostAddress())) 207 | val.getValue().sendMessage(reci); 208 | } 209 | 210 | } else if(reci.getType().equals("raisehand")) { 211 | mainframe.addSession("[" + socket.getInetAddress().getHostAddress() + "] 举手"); 212 | mainframe.showRaiseHand("[" + socket.getInetAddress().getHostAddress() + "] 举手"); 213 | } else if(reci.getType().equals("tasklist")) { 214 | taskViewFrame.getFrame().view(reci); 215 | System.out.println(reci); 216 | } 217 | } 218 | //System.out.println(4); 219 | } catch (IOException e) { 220 | listening = false; 221 | if (socketStatusListener != null) { 222 | int status = parseSocketStatus(e); 223 | socketStatusListener.onSocketStatusChanged(socket, 224 | status, e); 225 | } 226 | e.printStackTrace(); 227 | return;// 终止线程继续运行,这里也可以使用continue 228 | } finally { 229 | mainframe.addSession("[" + socket.getInetAddress().getHostAddress() + "] 已下线"); 230 | ServerThread.removeUserList(socket.getInetAddress().getHostAddress()); 231 | mainframe.setOnlineMember("当前在线人数为:" + ServerThread.getUserList()); 232 | ServerShotHandler.get(socket.getInetAddress().getHostAddress()).setVisible(false); 233 | } 234 | 235 | } 236 | } 237 | 238 | private int parseSocketStatus(IOException e) { 239 | if (SocketException.class.isInstance(e)) { 240 | String msg = e.getLocalizedMessage().trim(); 241 | if ("Connection reset".equalsIgnoreCase(msg)) { 242 | return SocketStatusListener.STATUS_RESET; 243 | } else if ("Socket is closed".equalsIgnoreCase(msg)) { 244 | return SocketStatusListener.STATUS_CLOSE; 245 | } else if ("Broken pipe".equalsIgnoreCase(msg)) { 246 | return SocketStatusListener.STATUS_PIP_BROKEN; 247 | } 248 | 249 | } 250 | return SocketStatusListener.STATUS_UNKOWN; 251 | } 252 | 253 | /** 254 | * listen:(这里用一句话描述这个方法的作用).
255 | * TODO(这里描述这个方法适用条件 – 可选).
256 | * 257 | */ 258 | public void startListener(SocketStatusListener ssl) { 259 | listening = true; 260 | this.socketStatusListener = ssl; 261 | start(); 262 | } 263 | 264 | } 265 | 266 | 267 | /** 268 | * @author Administrator 269 | * 写操作进程 270 | */ 271 | public class WriterTask extends Thread{ 272 | 273 | private PrintWriter bufferedWriter; 274 | 275 | private String msg = null; 276 | 277 | private Socket socket = null; 278 | 279 | public WriterTask(Socket socket) throws IOException { 280 | this.bufferedWriter = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8")); 281 | this.socket = socket; 282 | } 283 | 284 | /** 285 | * finishTask:(这里用一句话描述这个方法的作用).
286 | * TODO(这里描述这个方法适用条件 – 可选).
287 | * @throws IOException 288 | * 289 | */ 290 | public void finish() throws IOException { 291 | if(bufferedWriter!=null && socket!=null) 292 | { 293 | if(!socket.isOutputShutdown()) 294 | { 295 | socket.shutdownOutput(); 296 | } 297 | bufferedWriter.close(); 298 | } 299 | } 300 | 301 | /* (non-Javadoc) 302 | * @see java.lang.Runnable#run() 303 | */ 304 | @Override 305 | public synchronized void run() { 306 | bufferedWriter.println(msg); 307 | bufferedWriter.flush(); 308 | //System.out.println(msg); 309 | } 310 | 311 | public void send(String msg){ 312 | this.msg = msg; 313 | //System.out.println(msg); 314 | new Thread(this).start(); 315 | } 316 | 317 | } 318 | 319 | } -------------------------------------------------------------------------------- /src/DesktopServerUI/ServerMainFrame.java: -------------------------------------------------------------------------------- 1 | package DesktopServerUI; 2 | //教师端主界面 3 | import java.awt.*; 4 | import java.awt.event.ActionEvent; 5 | import java.awt.event.ActionListener; 6 | import java.awt.event.InputEvent; 7 | import java.awt.event.MouseAdapter; 8 | import java.awt.event.MouseEvent; 9 | import java.net.URL; 10 | import java.util.ArrayList; 11 | import java.util.Iterator; 12 | import java.util.Map; 13 | import java.util.Map.Entry; 14 | 15 | import javax.swing.*; 16 | 17 | import commonUI.watchFrame; 18 | 19 | 20 | import CommonClass.Information; 21 | import DesktopServerProcess.ServerShotHandler; 22 | import DesktopServerProcess.ServerThread; 23 | 24 | public class ServerMainFrame extends JFrame { 25 | /** 26 | * 27 | */ 28 | private static final int total = 30; 29 | private static final long serialVersionUID = 1L; 30 | private static ServerMainFrame servermainframe; 31 | static private ArrayList ips = new ArrayList(); 32 | public static void ClearIp() { 33 | ips.clear(); 34 | } 35 | public static void add(String ip) { 36 | ips.add(ip); 37 | } 38 | public static boolean checkboxes() { 39 | ClearIp(); 40 | for(int i=0; i 2) 189 | object.removeItemAt(2); 190 | object.addItem(ip); 191 | object.setSelectedIndex(object.getItemCount() - 1); 192 | } 193 | public class Action implements ActionListener { 194 | 195 | @Override 196 | public void actionPerformed(ActionEvent e) { 197 | // TODO Auto-generated method stub 198 | if(e.getSource() == tranFileBtn) { 199 | if(checkboxes()) { 200 | FileFrame.setIps(ips); 201 | singleTranFileFrame.setVis(true); 202 | } else { 203 | javax.swing.JOptionPane.showMessageDialog(null, "您未选择任何计算机,不能进行文件传输!", "警告", JOptionPane.ERROR_MESSAGE); 204 | } 205 | } else if(e.getSource() == send) { 206 | if(msg.getText().length() < 1) return; 207 | if(object.getSelectedItem().equals("至全体")) { 208 | Iterator> iter = ServerThread.getUser(); 209 | while(iter.hasNext()) { 210 | Map.Entry val = iter.next(); 211 | System.out.println("interface : " + val); 212 | val.getValue().sendMessage(Information.createSession("Server", msg.getText(), "all")); 213 | } 214 | addSession("[to all]" + msg.getText()); 215 | } else { 216 | ServerThread.getServerThread((String)object.getSelectedItem()).sendMessage(Information.createSession("Server", msg.getText(), (String)object.getSelectedItem())); 217 | addSession("[to" + (String)object.getSelectedItem() + "]" + msg.getText()); 218 | } 219 | 220 | msg.setText(null); 221 | } else if(e.getSource() == prtScBtn) { 222 | statu = 1 - statu; 223 | if(statu == 1) { 224 | prtScBtn.setText("关闭广播"); 225 | ServerShotHandler.getThread().openBroadcast(); 226 | } else { 227 | prtScBtn.setText("屏幕广播"); 228 | ServerShotHandler.getThread().closeBroadcast(); 229 | } 230 | } else if(e.getSource() == shutdown_upBtn) { 231 | if(!checkboxes()) { 232 | javax.swing.JOptionPane.showMessageDialog(null, "您未选择任何计算机,不能关机!", "警告", JOptionPane.ERROR_MESSAGE); 233 | } else { 234 | for(String ip:ips) { 235 | ServerThread.getServerThread(ip).sendMessage(new Information("cmd", "Server", "shutdown -s -t 0", ip)); 236 | } 237 | } 238 | } 239 | } 240 | 241 | } 242 | public void setOnlineMember(String value) { 243 | onlineMember.setText(value); 244 | } 245 | 246 | private JButton createBtn(String text, URL url) { 247 | ImageIcon ii = new ImageIcon(url); 248 | Image image = ii.getImage(); 249 | Image smallImage = image.getScaledInstance(64,64,Image.SCALE_FAST); 250 | JButton btn = new JButton(text, new ImageIcon(smallImage)); 251 | 252 | btn.setPreferredSize(new Dimension(64, 64)); 253 | btn.setFont(new Font("宋体", Font.PLAIN, 15)); 254 | btn.setMargin(new Insets(0, 0, 0, 0)); 255 | btn.addActionListener(new Action()); 256 | return btn; 257 | } 258 | public void addSession(String content) { 259 | session.append(content + "\r\n"); 260 | JScrollBar jsb = sessionRoll.getVerticalScrollBar(); 261 | jsb.setValue(jsb.getMaximum() + 1); 262 | } 263 | 264 | public FileFrame getSingleTranFileFrame() { 265 | return singleTranFileFrame; 266 | } 267 | 268 | public void setSingleTranFileFrame(FileFrame singleTranFileFrame) { 269 | this.singleTranFileFrame = singleTranFileFrame; 270 | } 271 | public void showRaiseHand(String value) { 272 | try { 273 | raisehandframe.setText(value); 274 | } catch (InterruptedException e) { 275 | // TODO Auto-generated catch block 276 | e.printStackTrace(); 277 | } 278 | } 279 | 280 | public int getStatu() { 281 | return statu; 282 | } 283 | 284 | public void setStatu(int statu) { 285 | this.statu = statu; 286 | } 287 | 288 | 289 | } 290 | --------------------------------------------------------------------------------