CN P8
CN P8
import java.net.*;
import java.io.*;
while (true) {
// Read input from the server console
String message = reader.readLine();
if (message.equalsIgnoreCase("exit")) {
System.out.println("Server is shutting down...");
break;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (socket != null && !socket.isClosed()) {
socket.close();
}
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
2. Create a file named Client.java with the following code:
import java.net.*;
if (message.equalsIgnoreCase("exit")) {
System.out.println("Server has shut down the connection.");
Computer Network Lab Manual
break;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (socket != null && !socket.isClosed()) {
socket.close();
}
}
}
}
javac Server.java
javac Client.java
java Client
java Server
6. Server Output
7. Client Output