OOP Lab Task 5
De la WikiLabs
Versiunea din 14 decembrie 2013 23:20, autor: Rhobincu (discuție | contribuții) (Pagină nouă: == Required Tutorials == * The Object Oriented Paradigm; Classes and Objects * Notions About the Java Language * Writing and Executing a Java Program * [[Java Syntax; A P...)
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
- Write a class ServerPeer, which should run as a separate thread and talk to a remote client. This thread should:
- deserialize objects of type Message sent by the remote client and send them to the Server instance;
- have a method that can send Message objects to the remote client, if the client name is equal to the contents of the receiver field of the message, or if that field is null.
- store the name of the remote client;
- The name of a client is changed only when it sends an object of type SystemMessage in which field type has the value TYPE_CHANGE_NAME. If the name is not already taken by another client, the change is made, and a new object of type SystemMessage is sent to the client, in which field type equals TYPE_OK. Otherwise, if the name is taken, the field type for the response object should have the value TYPE_ERROR;
- Change class Server so that it should:
- contain references to objects of type ServerPeer, one object per connected client;
- create a new ServerPeer for each new connected client, and run it as a separate thread;
- receive and dispatch all Messages from and to all the ServerPeers;
- automatically remove all disconnected ServerPeers.
Hint: Use class java.util.ArrayList.
- Change class client so that, on top of the existing functionality, it should also deserialize objects of type Message from the stream and display them in the console. Also, during the initial connection, it should send to the server an object of type SystemMessage designed to set the client name on the server. If the reply is TYPE_ERROR, the program will exit.