implement all TODO taks

This commit is contained in:
2026-06-19 16:52:29 +03:30
parent 89a7be30f4
commit d18248cfe9
3 changed files with 46 additions and 15 deletions
+17 -7
View File
@@ -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) {