D- ASEP SERVER PROGRAM

 What does ASP Server do?

How does ASEP Server work?
Figure 10: The ASEP Server Framework

Figure 10 shows the general working schema of ASEP Server Program. Since the program must handle many numbers of ASP and AEP clients that are connected from different machines at the same time, it creates a new thread of control for each client to handle their requests concurrently.

For the allocation of the received files in an organized way, the ASEP Server uses a simple and hierarchical directory structure as the figure 11 shows. For each course there is a specific directory and all the related data about the course is kept in this directory. Each course directory has different sub directories for every given assignment. The received assignment and feedback files (if attached) are stored in these sub directories. Since the ASEP Server knows the owner of the each received file, simply it renames it with the student’ s student ID number in order to provide uniqueness in accessing the files when needed. Since each given assignment and feedback has a specific file format, simply the received assignment files are renamed as "SID" + "." + "Format", and the attached assignment feedback files are renamed as "SID" + ". fdb". 

 Figure 11: A simple directory structure to store the assignments.
ASEP Server mainly perform six different type of operations. First one is the IP CHECK operation. It simply confirms the IP number that is entered in the clients’ login process. Unless this IP number is confirmed, the users can not log on to the system. The second type of operation is the NEW DIRECTORY operation. This operation is requested by only AEP clients. When an AEP client user wants to give a new assignment, the corresponding new directory is created by the ASEP Server upon request. The third type of operation is ASP ASSIGNMENT. It receives the submitted assignment files from the ASP clients and stores them in the corresponding course and assignment directories after renaming them in a unique way. This operation is requested by only ASP clients. The fourth one is AEP ASSIGNMENT. It submits the requested assignment files to the AEP clients for evaluation.
This operation is requested by only AEP clients. The fifth type of operation is AEP FEEDBACK. It receives the submitted assignment feedback files from the AEP clients and stores them in the corresponding course and assignment directories after renaming them in a unique way. This operation is requested by only AEP clients. The sixth type of operation is ASP FEEDBACK. It submits the requested assignment feedback 
Figure 12: ASEP Server

files to the ASP clients and it is requested by only ASP clients.  Figure 12 shows an instant view of the server program when it is receiving an assignment file. The program displays the information of which client is connected from where and when. When the file is completely received the program will display the inpormation of which client submitted which file for which course and assignment type.

In the below, you see the code segment that performs the ASP ASSIGNMENT operation. It represents a simple protocol between the client and the server programs. First, the server reads the required information including the course name, assignment type, assignment file format, student login and file size, then it opens a local disk file for output, reads the submitted data from the socket’s input stream into a buffer and writes the buffer contents to the opened disk file. After receiving all the data it sends an acknowledgement data to the ASP client to indicate that submission operation is completed succesfully.

// READ THE ESSENTIAL DATA
courseName = DinS.readUTF() ;
assignmentType = DinS.readUTF() ;
assignmentFileFormat = DinS.readUTF() ;
fileName = DinS.readUTF() ;
fileSize = DinS.readLong();
studentLogin = DinS.readUTF() ;
msg="ASP Client [" + studentLogin +"] is connected from " + clientAddress.getLocalHost()
+" at " + connectionDate.toString();
control.displayMsg(msg);
String newFileName= studentLogin + "." + assignmentFileFormat;
// OPEN A NEW DISK FILE
OutputStream outFile= new FileOutputStream ( "Courses\\" + courseName + "\\" +
assignmentType + "\\" + newFileName);
long readB=0;
// READ FROM INPUT SOCKET STREAM WRITE TO DISK FILE
while ( readB != fileSize ) {
int t = inS.read(dataBuffer);
outFile.write(dataBuffer,0,t);
readB = readB + t;
}
outFile.flush();
outFile.close();
control.displayMsg( "ASP Client [" + studentLogin +"] submitted the
file "+ fileName + " for " + assignmentType +
" of the course " + courseName + " succesfully.");
// SEND THE ACKNOWLEDGEMENT DATA
DoutS.writeUTF("THE END");
DoutS.flush();

The code below is the segment where the AEP ASSIGNMENT operation is performed. It is similar to the above one. First, the server reads the required information including the course name, assignment type, assignment file format, user login and student login then it opens the corresponding local disk file for input, reads the input data in to a buffer and writes the buffer contents to the socket’s output stream. After sending all the data it waits for an acknowledgement data from the ASP client to finish the operation succesfully.

// READ THE ESSENTIAL DATA
UserLogin = DinS.readUTF();
CourseName = DinS.readUTF();
AssignmentType = DinS.readUTF();
AssignmentFileFormat = DinS.readUTF();
studentLogin = DinS.readUTF();
msg = "AEP Client [" + userLogin +"] is connected from " +
clientAddress.getLocalHost() + " at " +
connectionDate.toString();
control.displayMsg(msg);
// CREATE A NEW FILE
File F = new File("Courses\\" + courseName + "\\" + assignmentType,
StudentLogin + "." + assignmentFileFormat);
// GET THE FILE SIZE
fileSize = F.length();
DoutS.writeLong(fileSize);
// OPEN THE CORRESPONDING DISK FILE
InputStream dataIn=new FileInputStream(F);
long gone =0;
double goneD =0;
// READ THE DATA FROM THE DISK FILE AND WRITE TO SOCKET’S OUTPUT STREAM
while ( dataIn.available() > 0 ) {
int length = dataIn.read(dataBuffer);
outS.write(dataBuffer,0,length);
}
// WAIT FOR THE ACKNOWLEDGEMENT DATA
if(DinS.readUTF().equals("THE END")){
control.displayMsg( assignmentType + " file of the course " +
courseName + " is send succesfully to the AEP Client [" +
userLogin +"].");
}