Diferență între revizuiri ale paginii „OOP Lab Task 6”

De la WikiLabs
Jump to navigationJump to search
(Zhascsi a redenumit pagina OOP Lab Task 6 în OOP Lab Task 7)
 
Linia 1: Linia 1:
#REDIRECTEAZA [[OOP Lab Task 7]]
+
== Required Tutorials ==
 +
 
 +
* [[The Object Oriented Paradigm; Classes and Objects]]
 +
* [[Notions About the Java Language]]
 +
* [[Writing and Executing a Java Program]]
 +
* [[Java Syntax; A Program's Lexical Structure]]
 +
* [[Coding Conventions]]
 +
* [[Advanced Notions About Object Oriented Programming]]
 +
* [[Java Application Programming Interface (API) (EN)]]
 +
* [[Exception Handling]]
 +
* [[Input/Output Streams]]
 +
* [[Serialization]]
 +
* [[Network Sockets]]
 +
* [[Concurrent Programming - Threads]]
 +
 
 +
== 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 [http://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html 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''':
 +
<syntaxhighlight lang="java">
 +
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!");
 +
}
 +
</syntaxhighlight>

Versiunea de la data 18 noiembrie 2015 00:01

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