From f4f4b9dc81042f5bbe68660f064d87099ebf0bb0 Mon Sep 17 00:00:00 2001
From: Hai HoDac <hhodac@student.unimelb.edu.au>
Date: Fri, 25 Oct 2019 13:18:15 +1100
Subject: [PATCH] Client: _ Fixed default username _ No input arguments needed
 Syntax: java -jar Client.jar

Server:
_ Add one compulsory input argument: server ip address
Syntax: java -jar Server.jar <host ip address>
---
 src/client/Client.java |  6 +++---
 src/server/Server.java | 26 ++++++++++++++------------
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/client/Client.java b/src/client/Client.java
index a9ca1b3..acfe956 100644
--- a/src/client/Client.java
+++ b/src/client/Client.java
@@ -93,9 +93,9 @@ public class Client
     }
 
 
-    public Client(String username) throws RemoteException, NoSuchProviderException, NoSuchAlgorithmException
+    public Client() throws RemoteException, NoSuchProviderException, NoSuchAlgorithmException
     {
-        this.defaultUserName = username;
+        this.defaultUserName = DEFAULT_USERNAME;
         this.clientUpdate = new ClientUpdate(this);
         this.chatUpdate = new ChatUpdate(this);
         this.drawingUpdate = new DrawingUpdate(this);
@@ -108,7 +108,7 @@ public class Client
     {
         try
         {
-            Client client = new Client(args[0]);
+            Client client = new Client();
             client.showStartScreen();
         }
         catch (Exception e)
diff --git a/src/server/Server.java b/src/server/Server.java
index 9e0084d..b65b320 100644
--- a/src/server/Server.java
+++ b/src/server/Server.java
@@ -50,7 +50,7 @@ public class Server
         {
             Server server = new Server();
 
-            server.run();
+            server.run(args[0]);
         }
         catch( Exception e )
         {
@@ -58,15 +58,15 @@ public class Server
         }
     }
 
-    public void run() throws RemoteException
+    public void run(String serverIP) throws RemoteException
     {
-        String serverIP = "";
-        try {
-            InetAddress inetAddress = InetAddress.getLocalHost();
-            serverIP = inetAddress.getHostAddress();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+//        String serverIP = "";
+//        try {
+//            InetAddress inetAddress = InetAddress.getLocalHost();
+//            serverIP = inetAddress.getHostAddress();
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
 
         System.setProperty("java.rmi.server.hostname", serverIP);
 
@@ -91,16 +91,18 @@ public class Server
 
         System.out.println("Server is ready");
 
-        printIP();
+        printIP(serverIP);
     }
 
-    private void printIP()
+    private void printIP(String serverIP)
     {
         InetAddress inetAddress = null;
 
         try
         {
-            inetAddress = InetAddress.getLocalHost();
+            if (serverIP.isEmpty()) {
+                inetAddress = InetAddress.getLocalHost();
+            } else inetAddress = InetAddress.getByName(serverIP);
         }
         catch (UnknownHostException e)
         {
-- 
GitLab