OOP Lab Task 6: Diferență între versiuni

De la WikiLabs
Jump to navigationJump to search
Fără descriere a modificării
Linia 13: Linia 13:
* [[Network Sockets]]
* [[Network Sockets]]
* [[Concurrent Programming - Threads]]
* [[Concurrent Programming - Threads]]
* [[Graphical User Interface (GUI) - Java Swing and JavaFX]]


== Requirements ==
== Requirements ==

Versiunea de la data 12 ianuarie 2016 19:09

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!");
}