Skip to content

Commit

Permalink
Remove redundant error message in Server and added message and respon…
Browse files Browse the repository at this point in the history
…se for connectToServer
  • Loading branch information
Rishad11 committed Mar 6, 2024
1 parent b165fcb commit 95f5447
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/main/java/org/fungover/thunder/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import java.net.Socket;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;

import static org.fungover.thunder.Main.logger;

public class Client {
private final String clientId;
Expand Down Expand Up @@ -39,7 +42,15 @@ public void connectToServer(String serverAddress, int serverPort) throws IOExcep
try (Socket socket = new Socket(serverAddress, serverPort);
ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
ObjectInputStream in = new ObjectInputStream(socket.getInputStream())) {
this.connected = true;

out.writeObject("Hello from " + clientId);
String response = (String) in.readObject();

if ("Connection successful".equals(response)) {
this.connected = true;
}
} catch (ClassNotFoundException e) {
logger.log(Level.SEVERE, "Error during connection", e);
}
}
}
1 change: 0 additions & 1 deletion src/main/java/org/fungover/thunder/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public void start() throws IOException {
public void stop(){
try {
serverSocket.close();
System.out.println("Server stopped");
} catch (IOException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
Expand Down

0 comments on commit 95f5447

Please sign in to comment.