This commit is contained in:
2026-06-20 00:17:32 +03:30
parent 240eac0504
commit daa9451984
4 changed files with 193 additions and 8 deletions
@@ -1,6 +1,20 @@
package com.university.chat.Client;
import com.university.chat.Common.ChatMessage;
import com.university.chat.Server.ClientSession;
import com.university.chat.Server.UserManager;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
public class chatClient {
public static final UserManager userManager =
new UserManager();
public static void main() {
// TODO: Connecting to the server
// 1. Create a socket and connect to the server
@@ -9,11 +23,20 @@ public class chatClient {
// 2. Get the username, and send a LOGIN ChatMessage with that username
// 3. Start a new Thread running a ServerListener(in) so incoming
// messages are handled concurrently.
ServerSocket serverSocket;
try{
serverSocket =new ServerSocket(5000);
System.out.println("Server started");
} catch (Exception e) {
throw new RuntimeException(e);
}
while (true){
try {
// TODO: Program loop — read a line from the console and act on it:
// - "/msg <user> <text>" -> build & send a PRIVATE_MESSAGE
// - "/msg <user> <text>" -> build & send a PRIVATE_MESSAGE
// - "/users" -> build & send a USER_LIST request
// - "/sendfile <user> <path>" -> read the file into a byte[]
// (you can use TransferProgress
@@ -21,6 +44,18 @@ public class chatClient {
// and send it as a FileMessage
// - anything else -> send a PUBLIC_MESSAGE
// Remember to flush() the output stream after writeObject().
Socket socket =
serverSocket.accept();
ClientSession session =
new ClientSession(
socket,
userManager
);
new Thread(session).start();
} catch (Exception e){
System.out.println("command failed: " + e.getMessage());
}