Question
Message passing Create a two way message passing objects. Message Object: Complete the provided message class to represent three types of messages. The message types
Message passing
Create a two way message passing objects.
Message Object: Complete the provided message class to represent three types of messages. The message types are: login, text, logout. The message type is simply a String attribute that represents the type. For example, login messages should set type =“login”. Once the message type attribute is set, it should not be changed by client code. The message class is used for sending messages between server and client objects. The status and text attributes may be changed as needed before sending the message object.
Server Object: The server listens for incoming connections from clients. On receiving an incoming connection, create a new thread for handling this connection until it is closed. This will need to be a two way connection. The server does nothing with the new connection until a ‘login message’ is received from the client. On receipt of the ‘login message’, the server changes the status of this login message to ‘success’ and returns this object to the client. If the client has sent a ‘login message’, the server will accept ‘logout message’ messages. On receipt, ‘logout message’ will be returned with status of ‘success’, then the connection will be closed by the server and the thread terminates. If the client hassent a ‘login message’, the server will accept ‘text message’messages. On receipt of ‘text message’, the text of text messages will be changed to all caps. The message is then returned to theclient.
Client Object: Client connects to a listening server object. Onconnection, pass a ‘login message’ to the server. The server willreturn the login message with a status of ‘success’. The clientthen prompts the user for text to send to the server. Text is sentusing a ‘text message’. On receipt of ‘text message’ from server,display the text field to the user. If the user enters, ‘logout’,the client sends a ‘logout message’ to the server.
Message.java
import java.io.Serializable;public class Message implements Serializable { protected String type; protected String status; protected String text; public Message(){ this.type = "Undefined"; this.status = "Undefined"; this.text = "Undefined"; } public Message(String type, String status, String text){ this.type = setType(type); this.status = setStatus(status); this.text = setText(text); } private void setType(String type){ } public void setStatus(String status){ } public void setText(String text){ } public String getType(){ } public String getStatus(){ } public String getText(){ }}
Step by Step Solution
3.43 Rating (159 Votes )
There are 3 Steps involved in it
Step: 1
Serverjavaimport javaio import javanet import javautil public class Server private ServerSocket serverSocketprivate List clients public Serverint port ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started