📄 netexamsystem_server.java~61~
字号:
package testovernet;
import java.io.*;
import java.net.*;
public class NetExamSystem_Server {
public static void main(String[] args) {
ServerSocket serverSocket = null;
ExamAdmin examAdmin = new ExamAdmin();
try {
serverSocket = new ServerSocket(9999);
}
catch (IOException e) {
e.printStackTrace();
}
while (true) {
try {
Socket servSocket = serverSocket.accept();
InputStream servInput = servSocket.getInputStream();
OutputStream servOutput = servSocket.getOutputStream();
DataInputStream dataInput = new DataInputStream(servInput);
DataOutputStream dataOutput = new DataOutputStream(servOutput);
ObjectInputStream objInput = new ObjectInputStream(servInput);
ObjectOutputStream objOutput = new ObjectOutputStream(
servOutput);
Student stuFromClient = (Student) objInput.readObject();
System.out.println("Student " + stuFromClient.name +
" is connected. "
+ "\n" + "Authenticating...");
//stuFromClient.printStudentInfo();
boolean isStudent = examAdmin.isStudentInDatabase(stuFromClient.
testNum, stuFromClient.name);
if (isStudent == true) {
dataOutput.writeUTF("\nAuthenticated!"+"\nYou are qulified to take a test!\n"
+"Please input what type of question you want"
+ " to answer and how many?");
/* dataOutput.writeUTF("You are qulified to take a test!\n"
+ "Let's start:"); */
dataOutput.writeUTF("Eligible");
String questionType = dataInput.readUTF();
int questionAmount = dataInput.readInt();
examAdmin.sendPaperToStudent(questionType, questionAmount,
objOutput);
examAdmin.getTestPaperAfterExamFromStudent(questionAmount,
objInput);
examAdmin.caculatorStudentScore(questionAmount, dataOutput);
examAdmin.recordStudentScoreToDatabase();
}
else {
dataOutput.writeUTF(
"\nSorry,You are not qulified to take a test!\n"
+ "Please make yourself qulified, Bye!!!");
dataOutput.writeUTF("NotEligible");
}
servInput.close();
servOutput.close();
servSocket.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -