Develop #1
@@ -1,15 +1,26 @@
|
|||||||
package com.university.chat.Server;
|
package com.university.chat.Server;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.ServerSocket;
|
||||||
|
import java.net.Socket;
|
||||||
|
|
||||||
public class ChatServer {
|
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 void main(String[] args) {
|
private static final UserManager userManager = new UserManager();
|
||||||
// TODO: Create a ServerSocket
|
private static final int port = 9000;
|
||||||
|
|
||||||
// TODO: In an infinite loop:
|
public static void main(String[] args) throws IOException {
|
||||||
// accept an incoming client connection
|
|
||||||
// make a new thread running ClientSession for each user.
|
try( ServerSocket serverSocket = new ServerSocket(port)){
|
||||||
|
System.out.println("Server started on port " + port);
|
||||||
|
while(true){
|
||||||
|
Socket clientSocket = serverSocket.accept();
|
||||||
|
Thread clientThread = new Thread(new ClientSession(clientSocket,userManager));
|
||||||
|
clientThread.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e){
|
||||||
|
System.out.println("server error: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public class ClientSession implements Runnable {
|
|||||||
public ClientSession(Socket socket, UserManager userManager) {
|
public ClientSession(Socket socket, UserManager userManager) {
|
||||||
// TODO : Create an ObjectOutputStream from socket.getOutputStream()
|
// TODO : Create an ObjectOutputStream from socket.getOutputStream()
|
||||||
// and an ObjectInputStream from socket.getInputStream().
|
// and an ObjectInputStream from socket.getInputStream().
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user