[CT414]: Assignment 1 working
This commit is contained in:
@ -21,10 +21,10 @@ public class ApplicationClient {
|
||||
System.out.println("ApplicationHandler found in registry");
|
||||
|
||||
// login
|
||||
System.out.println("Enter your username\n> ");
|
||||
System.out.printf("Enter your username\n> ");
|
||||
String username = scanner.nextLine();
|
||||
|
||||
System.out.println("Enter your password\n> ");
|
||||
System.out.printf("Enter your password\n> ");
|
||||
String password = scanner.nextLine();
|
||||
|
||||
long sessionID = handler.login(username, password);
|
||||
@ -43,7 +43,7 @@ public class ApplicationClient {
|
||||
// answer questiosn
|
||||
for (int i = 0; i < form.getTotalQuestions(); i++) {
|
||||
System.out.println("Q" + i + ": " + form.getQuestion(i));
|
||||
System.out.println("A> ");
|
||||
System.out.printf("A> ");
|
||||
form.answerQuestion(i, scanner.nextLine());
|
||||
}
|
||||
System.out.println("Form filled successfully.");
|
||||
|
@ -1,10 +1,12 @@
|
||||
package implementations;
|
||||
|
||||
import interfaces.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.rmi.*;
|
||||
|
||||
public class ApplicationFormV1 implements ApplicationForm {
|
||||
public class ApplicationFormV1 implements ApplicationForm, Serializable {
|
||||
private String formInfo = "University of Galway Application Form - Version 1";
|
||||
private String[] questions = new String[5];
|
||||
private String[] answers = new String[5];
|
||||
|
@ -38,7 +38,7 @@ public class ApplicationHandlerImpl implements ApplicationHandler {
|
||||
@Override
|
||||
public void submitApplicationForm(long sessionID, ApplicationForm applicationForm) throws RemoteException, InvalidSessionIDException {
|
||||
if (sessions.contains(sessionID)) {
|
||||
String filename = applicationForm.getName().replace("\\s", "_") + ".txt";
|
||||
String filename = applicationForm.getName().replaceAll("\\s", "_") + ".txt";
|
||||
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
|
||||
System.out.println("Saving application form to file: " + filename);
|
||||
|
@ -1,14 +1,17 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
src_path="/home/andrew/edu/year4/semester2/CT414/assignments/assignment1/code/src"
|
||||
|
||||
# compile code
|
||||
javac -d . server/*.java client/*.java interfaces/*.java implementations/*.java
|
||||
javac -d . server/*.java client/*.java interfaces/*.java implementations/*.java
|
||||
|
||||
# start rmi registry
|
||||
rmiregistry -J-Djava.rmi.server.codebase=file:$src_path &
|
||||
trap "kill $! 2>/dev/null" EXIT
|
||||
# start rmi registry (in a new terminal)
|
||||
$TERM -e rmiregistry -J-Djava.rmi.server.codebase=file:$src_path &
|
||||
sleep 1
|
||||
|
||||
# start server
|
||||
java -cp $src_path -Djava.rmi.server.codebase=file:$src_path/ server.ApplicationServer &
|
||||
trap "kill $! 2>/dev/null" EXIT
|
||||
# start server (in a new terminal)
|
||||
$TERM -e java -cp $src_path -Djava.rmi.server.codebase=file:$src_path/ server.ApplicationServer &
|
||||
sleep 1
|
||||
|
||||
# start client (in a new terminal)
|
||||
$TERM -e java -cp $src_path -Djava.rmi.server.codebase=file:$src_path/ client.ApplicationClient
|
||||
|
@ -1,6 +1,7 @@
|
||||
package server;
|
||||
|
||||
import implementations.ApplicationHandlerImpl;
|
||||
import interfaces.ApplicationHandler;
|
||||
|
||||
import java.rmi.Naming;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
@ -14,10 +15,10 @@ public class ApplicationServer {
|
||||
Registry registry = LocateRegistry.getRegistry();
|
||||
|
||||
// create applicationhandlerstub and bind it
|
||||
ApplicationHandlerImpl applicationHandler = new ApplicationHandlerImpl();
|
||||
ApplicationHandler applicationHandler = new ApplicationHandlerImpl();
|
||||
System.out.println("Instance of ApplicationHandlerImpl created");
|
||||
|
||||
ApplicationHandlerImpl stub = (ApplicationHandlerImpl) UnicastRemoteObject.exportObject(applicationHandler, 0);
|
||||
ApplicationHandler stub = (ApplicationHandler) UnicastRemoteObject.exportObject(applicationHandler, 0);
|
||||
Naming.rebind("ApplicationHandler", stub);
|
||||
System.out.println("Name rebind completed");
|
||||
|
||||
|
Reference in New Issue
Block a user