Skip to content

Commit

Permalink
Merge branch 'Bobcodiz:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Red-stevo authored Jul 30, 2024
2 parents 3de2018 + efbb774 commit 1a18509
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ChatApp/src/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Client {
public static void main(String[] args) {
String SERVER_IP = null;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the server ip address: ");
System.out.println("Enter the server IP address: ");
// Read the server IP address from the user input
SERVER_IP = scanner.nextLine();

Expand Down Expand Up @@ -46,8 +46,20 @@ public static void main(String[] args) {
// Send each user input message to the server
out.println(userMessage);
}
}catch (UnknownHostException e) {
// Handling UnknownHostException
System.err.println("Error: The IP address of the host could not be determined.");
System.err.println("Please check the IP address and try again.");
} catch (ConnectException e) {
// Handling ConnectException
System.err.println("Error: Unable to connect to the server. Connection refused.");
System.err.println("Possible causes:");
System.err.println("- The server is not running.");
System.err.println("- The IP address is incorrect.");
System.err.println("Please check the server status and the IP address then try again.");
} catch (IOException e) {
// Handle IO exceptions that may occur during client operation
// Handle other IO exceptions
System.err.println("Error: An I/O error occurred while trying to connect to the server.");
e.printStackTrace();
}
}
Expand Down
1 change: 1 addition & 0 deletions ChatApp/src/ClientHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public ClientHandler(Socket socket, Set<ClientHandler> clientHandlers) throws IO
public void run() {

try {

synchronized (clientHandlers) {
for (ClientHandler clientHandler : clientHandlers) {
clientHandler.setName(clientName);
Expand Down

0 comments on commit 1a18509

Please sign in to comment.