Develop #1

Open
Z.Gharagozloo.M wants to merge 4 commits from develop into main
Showing only changes of commit 7ff1217c76 - Show all commits
@@ -1,15 +1,30 @@
package com.university.chat.Server;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class ChatServer {
// TODO: declare a single shared UserManager instance (static final)
// This MUST be shared by all ClientSession threads so that
// broadcasting and private messaging work correctly.
public static final UserManager userManager = new UserManager();
public static void main(String[] args) {
// TODO: Create a ServerSocket
int port = 8080;
// TODO: In an infinite loop:
// accept an incoming client connection
// make a new thread running ClientSession for each user.
try (ServerSocket serverSocket = new ServerSocket(port)) {
//for catching multiple clients at the same time
while (true) {
//waiting for the client and catches it when it connects
Socket socket = serverSocket.accept();
//building a client session to get the socket
ClientSession clientSession = new ClientSession(socket, userManager);
//building a thread to this client
Thread SoketThread = new Thread(clientSession);
SoketThread.start();
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}