forked from AdvancedProgramming1404/HW-10-Socket-Programming
implemet Server Listener + chat server + part of client session
This commit is contained in:
@@ -1,12 +1,25 @@
|
||||
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)
|
||||
private static final UserManager usermanager = new UserManager() ;
|
||||
// This MUST be shared by all ClientSession threads so that
|
||||
// broadcasting and private messaging work correctly.
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws IOException {
|
||||
// TODO: Create a ServerSocket
|
||||
ServerSocket serverSocket = new ServerSocket(8080) ;
|
||||
while (true)
|
||||
{
|
||||
Socket socket = serverSocket.accept() ;
|
||||
ClientSession clientSession = new ClientSession(socket , usermanager) ;
|
||||
Thread thread = new Thread(clientSession) ;
|
||||
thread.start();
|
||||
}
|
||||
|
||||
// TODO: In an infinite loop:
|
||||
// accept an incoming client connection
|
||||
|
||||
Reference in New Issue
Block a user