OOP Lab Task 4
De la WikiLabs
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
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.