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

De la WikiLabs
Jump to navigationJump to search
Linia 15: Linia 15:
 
== Requirements ==
 
== Requirements ==
  
* Change the classes '''Message''' and '''SystemMessage''' so they can be serialized. Use '''serialVersionUID''' = 1 for '''Message''' and '''serialVersionUID''' = 2 for '''SystemMessage''';
+
# Implement a class called '''ClientPeer''' with the following characteristics:
* 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;
+
#* The class constructor takes as arguments a String (the user/sender name) and a reference to a pre-initialized Socket.
* 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()''';
+
#* The class implements two methods:
* Test the two classes by running them both in different consoles.
+
#** <code>void sendMessage(String message)</code> - creates a Message object and serializes it, utilising the available Socket.
 +
#** <code>void sendMessage(String message, String receiver)</code> - creates a PrivateMessage object and serializes it, utilising the available Socket.
 +
# Implement a class called '''TextClient''', which is executable (has a main method), with the following characteristics:
 +
#* The main method opens a Socket on the localhost (127.0.0.1) on port 9000
 +
#* While the socket connection is active, read strings of characters from the keyboard (utilizing the Console class - see [https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#console-- System.console()]) and call the sendMessage methods specified above (Note: You may choose any formatting to identify a private message, but please describe this format in the homework submission e-mail; one example is <code>/w John Hello!</code> which identifies a private message to user John, with the content "Hello!").
 +
# Implement a class called '''ServerPeer''' with the following characteristics:
 +
#* The class constructor takes as argument a reference to a pre-initialized Socket.
 +
#* While the socket connection is active, it deserializes objects of type Message and prints their formatted contents to the screen.
 +
# Implement a class called '''Server''', which is executable (has a main method), with the following characteristics:
 +
#* The main method must utilize an object of type '''ServerConfig''' to read a port number from a configuration file
 +
#* Utilizing the identified port number, opens a ServerSocket and listens to connections,
 +
#* Once a client is connected, creates a ServerPeer object, which utilizing the Socket obtained from the ServerSocket, reads objects from the stream, according to point 3 above.
 +
# Modify the Message and PrivateMessage classes such that they are serializable.

Versiunea de la data 12 decembrie 2014 09:57

Required Tutorials

Requirements

  1. Implement a class called ClientPeer with the following characteristics:
    • The class constructor takes as arguments a String (the user/sender name) and a reference to a pre-initialized Socket.
    • The class implements two methods:
      • void sendMessage(String message) - creates a Message object and serializes it, utilising the available Socket.
      • void sendMessage(String message, String receiver) - creates a PrivateMessage object and serializes it, utilising the available Socket.
  2. Implement a class called TextClient, which is executable (has a main method), with the following characteristics:
    • The main method opens a Socket on the localhost (127.0.0.1) on port 9000
    • While the socket connection is active, read strings of characters from the keyboard (utilizing the Console class - see System.console()) and call the sendMessage methods specified above (Note: You may choose any formatting to identify a private message, but please describe this format in the homework submission e-mail; one example is /w John Hello! which identifies a private message to user John, with the content "Hello!").
  3. Implement a class called ServerPeer with the following characteristics:
    • The class constructor takes as argument a reference to a pre-initialized Socket.
    • While the socket connection is active, it deserializes objects of type Message and prints their formatted contents to the screen.
  4. Implement a class called Server, which is executable (has a main method), with the following characteristics:
    • The main method must utilize an object of type ServerConfig to read a port number from a configuration file
    • Utilizing the identified port number, opens a ServerSocket and listens to connections,
    • Once a client is connected, creates a ServerPeer object, which utilizing the Socket obtained from the ServerSocket, reads objects from the stream, according to point 3 above.
  5. Modify the Message and PrivateMessage classes such that they are serializable.