OOP Lab Task 6

De la WikiLabs
Jump to navigationJump to search
Versiunea pentru tipărire nu mai este suportată și poate avea erori de randare. Vă rugăm să vă actualizați bookmarkurile browserului și să folosiți funcția implicită de tipărire a browserului.

Required Tutorials

Requirements

  • Modify class ClientPeer written for the previous assignment, making it into a thread which, in parallel with the main execution thread, has to read objects of type Message from the server and write them on the screen.
  • Modify class ServerPeer written for the previous assignment, making it into a thread. This new thread must read objects of type Message and PrivateMessage from the associated client and correctly distribute them to the other clients.
  • Modify class Server written for the previous assignment, such that when a new client connects, the Server main thread should create a new ServerPeer and start it as a Thread, and then return to blocking in method ServerSocket.accept(), waiting for a new incoming connection.
  • The server should not accept a new connection if the current number of connected clients is already equal to property MAX_CLIENTS read from the server.conf configuration file by the class ServerConfig.

Notes:

  • Class Server should keep a list of all the connected clients (objects of type ServerPeer). For this, you can use class java.util.ArrayList.
  • This list should be kept consistent, meaning new clients should be added, and disconnected clients should be removed.
  • This list should be available to the ServerPeer execution threads through synchronized methods.
  • To check if an object is instance of a specific class, you can use operator instanceof:
Object o = ois.readOject();
if(o instanceof String){
    String s = (String)o;
    System.out.print(s);
}else{
    System.out.print("The object is not a String!");
}

Submitting

  • The assignment will be evaluated automatically by the Web-CAT platform.
  • You could access the Web-CAT platform using the username and the password with which you acces the electronica.curs.pub.ro intranet.
  • Select the OOP Lab Task 6 assignment.
  • Submit your work as a single .zip archive (give it whatever name you choose) containing only the Java source code files.
  • Attention Any deviation from these instructions may lead to the loss of the entire amount of points.