OOP Lab Task 4: Diferență între versiuni

De la WikiLabs
Jump to navigationJump to search
 
Linia 16: Linia 16:


* Change the classes '''Message''' and '''SystemMessage''' so they can be serialized. Use '''serialVersionUID''' = 1 for '''Message''' and '''serialVersionUID''' = 2 for '''SystemMessage''';
* Change the classes '''Message''' and '''SystemMessage''' so they can be serialized. Use '''serialVersionUID''' = 1 for '''Message''' and '''serialVersionUID''' = 2 for '''SystemMessage''';
* Write a class '''Client''' which should only contain the '''main''' method. This should take three arguments, at runtime, representing a ''host'', a ''port'' and a ''username''. Create a network socket to connect to the specified server. Using class [http://docs.oracle.com/javase/7/docs/api/java/io/Console.html java.io.Console], read messages from the keyboard, instantiate objects of type '''Message''' with '''sender''' being the ''username'', '''receiver''' being '''null''' and '''content''' being the message read from the keyboard, and serialize the objects to the server. The client should only stop if forced by using '''Ctrl + c''' key combination;
* Write a class '''Client''' which should only contain the '''main''' method. This should take three arguments, at runtime, representing a ''host'', a ''port'' and a ''username''. Create a network socket to connect to the specified server. Using class [http://docs.oracle.com/javase/7/docs/api/java/io/Console.html java.io.Console], read messages from the keyboard, instantiate objects of type '''Message''' with '''sender''' being the ''username'', '''receiver''' being '''null''' and '''content''' being the message read from the keyboard, and serialize the objects to the server. The client should only stop if forced by using the '''Ctrl + c''' key combination;
* Write a class '''Server''' that should only contain the '''main''' method. It should receive a single argument at runtime, representing the ''port'' on which to listen for incoming connection. Once a client is connected, the server should continue to read objects of type '''Message''' from the input stream, and display them in the console by using method'''toString()''';
* Write a class '''Server''' that should only contain the '''main''' method. It should receive a single argument at runtime, representing the ''port'' on which to listen for incoming connection. Once a client is connected, the server should continue to read objects of type '''Message''' from the input stream, and display them in the console by using method '''toString()''';
* Test the two classes by running them both in different consoles.
* Test the two classes by running them both in different consoles.

Versiunea de la data 14 decembrie 2013 23:07

Required Tutorials

Requirements

  • Change the classes Message and SystemMessage so they can be serialized. Use serialVersionUID = 1 for Message and serialVersionUID = 2 for SystemMessage;
  • Write a class Client which should only contain the main method. This should take three arguments, at runtime, representing a host, a port and a username. Create a network socket to connect to the specified server. Using class java.io.Console, read messages from the keyboard, instantiate objects of type Message with sender being the username, receiver being null and content being the message read from the keyboard, and serialize the objects to the server. The client should only stop if forced by using the Ctrl + c key combination;
  • Write a class Server that should only contain the main method. It should receive a single argument at runtime, representing the port on which to listen for incoming connection. Once a client is connected, the server should continue to read objects of type Message from the input stream, and display them in the console by using method toString();
  • Test the two classes by running them both in different consoles.