|
|
Linia 16: |
Linia 16: |
| == Requirements == | | == Requirements == |
| | | |
− | * Write a class '''ServerPeer''', which should run as a separate thread and ''talk'' to a remote client. This thread should:
| + | Coming soon! |
− | ** 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 '''ServerPeer'''s.
| |
− | Hint: Use class [http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html 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.
| |