Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jzzjackz authored Jul 13, 2024
1 parent 0991ce4 commit 7980ba8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public Client(Socket socket, String username) {
// If an error occurred, the server will "closeEverything" in this order:
// Reader (Displays messages), Writer (Sends), socket (server)
closeEverything(bufferedReader, bufferedWriter, socket);
e.printStackTrace();
}
}
// If a user sends a message
Expand All @@ -39,6 +40,7 @@ public void sendMessage() {
bufferedWriter.write(username + ": " + messageToSend);
// New line
bufferedWriter.newLine();
System.out.println("Message sent!");
// Refresh
bufferedWriter.flush();
}
Expand All @@ -59,9 +61,11 @@ public void run() {
msgFromGroupChat = bufferedReader.readLine();
// Prints it so everyone can see the message.
System.out.println(msgFromGroupChat);

// If an error occurred, the server will "closeEverything" in this order:
} catch (IOException e) {
closeEverything(bufferedReader, bufferedWriter, socket);
System.out.println("Disconnected due to error.");
}
}
}
Expand All @@ -80,7 +84,7 @@ public void closeEverything(BufferedReader bufferedReader,BufferedWriter buffere
socket.close();
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("Disconnected due to error.");
}
}

Expand All @@ -89,6 +93,7 @@ public static void main(String[] args) throws IOException {
// Login system
System.out.println("Please enter your username: ");
String username = scanner.nextLine();
System.out.println("SERVER: You have connected to the server successfully!");
// Joins the server
// NOTE: IF YOU WANT TO JOIN SOMEONE ELSE'S SERVER, ASK THEM FOR THE SERVER IP AND PORT. REPLACE "localhost"
// AND "1234" WITH THE SERVER IP AND PORT GIVEN TO YOU
Expand Down

0 comments on commit 7980ba8

Please sign in to comment.