Question
Can someone help me with my java code. I believe I'm just missing a few things. CHAT CLIENT import ocsf.client.AbstractClient; public class ChatClient extends AbstractClient
Can someone help me with my java code. I believe I'm just missing a few things.
CHAT CLIENT
import ocsf.client.AbstractClient;
public class ChatClient extends AbstractClient
{
public ChatClient()
{
super("localhost",8300);
}
public void handleMessageFromServer(Object msg)
{
if (msg instanceof String)
{
//Display message
}
}
public void connectionException (Throwable exception)
{
System.out.println(exception.getMessage());
exception.printStackTrace();
}
public void connectionEstablished() {
}
}
public class TestChatClient
{
public TestChatClient(String host, int port)
{
}
public static void main(String[] args)
{
int port = Integer.parseInt(args[1]);
new TestChatClient(args[0], port);
}
}
ChatClient Implement a Java Class named ChatClient (ChatClient must extend AbstractClient that "Implement abstract methods" is selected when creating the ChatClientclass, Make sure The method description for ChatClient is given below: public ChatClient() Constructor for the ChatClient. The default host String should be set to "localhost". The default port number should be set to 8300. public void bandleMessageFromServec Object msg) Slot method that is invoked whenever the server sends a message to the client. For now, the method can simply display on the Console "Server Message sent to Client "+msg, where usg is the String contained within parameter msg public void connectionException (Throwable exception) Hook method that is invoked whenever an exception occurs while the Client is connecting to the Server. For now display the following messages to the Console I. Display a message Connection Exception Occurred" 2. The actual message set by the system within the exception input parameter 3. The stack trace associated with the exception input parameter public void Hook method that is invoked once the Client has successfully connected to the Server. For now, display the following message to the Console "Client Connected" TestChatClient Implement a second class named TestChatClient, The TestChatClient class should declare the following private Chatclient client; And implement only the following 2 methods public Testchatclient(String host, int port) Constructor. Accepts two input parameters- the host and the port. This Constructor should perform the following steps: 1. Instantiate a ChatClient objiect using the parameterized Constructor. 2. Invoke the open method on the ChatClient object 3. Send a String object to the server containing "Hello Server" public static void main (String ags) Accepts 2 command line arguments stored in acgs input parameter arstel -2 host name for the Sever These 2 values must be passed as arguments to the TehaCient Constructor ChatServer Modifications Modify the handleMessagefronclient. ChatServer class from lab 2in as follows: public void handleMessageFronci lenobject arge, ConnectionToClient, arg1) Slot method that is invoked whenever the client sends a message to the server. Typecast input parameter arge to a String object. Extract the client ID from argl (use getID method). Prepend the word "Client", followed by the client id (an integer), followed by the String object contained in arg0. Display the entire message on the Console Example message: Client 1 Hello Server After displaying the message from the Client, send the following String to the Client: "Hello ClientStep by Step Solution
There are 3 Steps involved in it
Step: 1
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