implement all TODO taks
This commit is contained in:
@@ -37,19 +37,29 @@ public class ChatClient {
|
||||
}
|
||||
|
||||
private void connectToServer() throws IOException {
|
||||
// TODO: create socket connection to host:port
|
||||
// TODO: initialize output stream (PrintWriter)
|
||||
// TODO: initialize input stream (BufferedReader)
|
||||
|
||||
socket = new Socket(host, port);
|
||||
out = new PrintWriter(socket.getOutputStream(), true);
|
||||
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
}
|
||||
|
||||
private void readUserInputAndSend() throws IOException {
|
||||
// TODO: read continuously from console
|
||||
// TODO: send each input line to server
|
||||
|
||||
String line;
|
||||
while((line = consoleReader.readLine()) != null) {
|
||||
out.println(line);
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
// TODO: close socket safely
|
||||
// TODO: release resources
|
||||
|
||||
try {
|
||||
if (socket != null && !socket.isClosed()) {
|
||||
socket.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error closing socket: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Reference in New Issue
Block a user