?? server.java
字號:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package server;/** * * @author Administrator */import java.io.*;import java.net.*;import java.util.*;class FileName implements FilenameFilter { String str=null; FileName (String s) { str="."+s; } public boolean accept(File dir,String name) { return name.endsWith(str); } }public class Server { public static void main(String args[]) { ServerSocket server=null; Socket you=null; while(true) { try { server=new ServerSocket(6666); } catch(IOException e1) { System.out.println("正在監聽"); } try { you=server.accept(); InetAddress address=you.getInetAddress(); System.out.println("客戶端的IP:"+address); } catch (IOException e) { } if(you!=null) { new Server_thread(you).start(); } else { continue; } } }}class Server_thread extends Thread{ int i=0; Socket socket=null; File file=null; DataOutputStream out=null; DataInputStream in=null; ReadTestquestion 讀取試題=null; boolean 通知考試界面考試用時=true; Server_thread(Socket t) { socket=t; try { in=new DataInputStream(socket.getInputStream()); out=new DataOutputStream(socket.getOutputStream()); } catch (IOException e) { } 讀取試題=new ReadTestquestion(); } public void run() { while(true) { String s=null; try { s=in.readUTF(); if(s.startsWith("列出考試文件")) { String 當前目錄=System.getProperty("user.dir"); File dir=new File(當前目錄); FileName fileTxt=new FileName("txt"); String fileName[]=dir.list(fileTxt); for(int i=0;i<fileName.length;i++) { out.writeUTF("考試文件:"+fileName[i]); } out.writeUTF("已經全部列出:"); } else if(s.startsWith("考試文件的名字:")) { String fileName=s.substring(s.indexOf(":")+1); 讀取試題.setFilename(fileName); 讀取試題.set完成考試(false); 通知考試界面考試用時=true; } else if(s.startsWith("讀取下一題")) { String contentTest=讀取試題.getTestContent(); out.writeUTF("試題內容:"+contentTest); if(通知考試界面考試用時==true) { long time=讀取試題.getTime(); out.writeUTF("考試用時:"+time); 通知考試界面考試用時=false; } if(讀取試題.get完成考試()) { out.writeUTF("考試結束:"); } } else if(s.startsWith("提交的答案:")) { String answer=s.substring(s.indexOf(":")+1); 讀取試題.setSelection(answer); } else if(s.startsWith("查看得分")) { int score=讀取試題.getScore(); String messages=讀取試題.getMessages(); out.writeUTF("分數:"+score+"\n"+messages); } } catch(IOException ee) { try{ socket.close(); } catch(Exception eee) { } System.out.println("客戶離開了"); break; } } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -