Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this Java Networking Assignment. Thanks You will be implementin

ID: 3605745 • Letter: I

Question

I need help with this Java Networking Assignment. Thanks

You will be implementing a text messaging application. You will have a seperate window for each person you are communicating with. The window will have as a title the IP address and port number of the person you are messaging with.

You will have a main window that allows you to initiate messaging sessions with other people based on their IP address and port number. Once you initiate a new messaging session, you will create a new window for that session. This window should also have a button to exit the program.

You will still have the receiving Thread which will handle all the incoming messages. However, your code will also keep track of the source IP addresses and port number along with the window containing that messaging session. If the source IP address and port number combination is a new one, you will have to open a new messaging window. Otherwise, the incoming message will be displayed in the existing window for that source IP address.

Each window will have the following components:

The title of the window should be the IP address and port number of the other side of the messaging session.

A section to display the messaging interaction. This window should contain the messages from both you and the person you are messaging with.

A section for you to type your reply.

A button to send your reply.

A button the close and end the messaging session.

You will be implementing a text messaging application. You will have a seperate window for each person you are communicating with. The window will have as a title the IP address and port number of the person you are messaging with. You will have a main window that allows you to initiate messaging sessions with other people based on their IP address and port number. Once you initiate a new messaging session, yo wll create a new window for that session. This window should also have a button to exit the program. You will still have the receiving Thread which will handle all the incoming messages. However, your code will also keep track of the source IP addresses and port number along with the window containing that messaging session If the source IP address and port number combination is a new one, you will have to open a new messaging window. Otherwise, the incoming message will be displayed in the existing window for that source IP address Each window wll have the following components: 1. The title of the window should be the IP address and port number of the other side of the messaging session. 2. A section to display the messaging interaction. This window should contain the messages from both you and the person you are messaging with. 3. A section for you to type your reply. 4. A button to send your reply. 5. A button the close and end the messaging session.

Explanation / Answer

Java provides java.net.* package for creating network related applications.

So you will have to use the classes present in this package. Since you have to maintain the reliable session, you will have to use TCP/IP sockets to maintain the reliable connection.

Java provides below two main classes:

1) ServerSocket class for accepting the client connections in the network.

2) Socket class for connecting to another person/client present in the network.

For creating User Interface for Text Messaging application, you can create it either in Java AWT (Abstract Window Toolkit) or in Java Swing, but you are recommended to use Java Swing.

First of all in main method, you will have to create a object of ServerSocket, and your main thread will continue accepting client connections forever unless you exit the application.

Like below sample code:

ServerSocket server = new ServerSocket(1234);

while (true) {

Socket clientSocket = server.accept();

String ipaddr = new String("Client Connected IP ::" + newSocket.getInetAddress());

Client client = new Client(newSocket);

Thread.sleep(500); //main thread to sleep

}

Then you can have class called Client, for each client object you will need to create a separate thread for reading and writing the message to the respective person.

class Client implements Runnable {

private Socket socket;

private Thread thread;

private JFrame frame;

// Then your other UI related fields.

public Client(Socket socket){

this.socket = socket;

// Create JFrame object and set it's title to client socket address and remote port.

//initialize your JFrame with JTextArea for messaging area, JTextFied for sending reply message, JButton to create send and exit button

}

public void run(){

// in this run method, your client will continue reading message from other person and to display it

// on JTextArea.

// Socket class provides getInputStream() method from which you can read the data and getOutputStream()

method through which you can write the data.

// Use Send button to register action listener, once this button is clicked, you can send the typed message in JTextField using socket's getOutputStream() method.

// You have to use addActionListener() method on exit button to close the entire session, for closing socket connection

}

}

Hope this helps for writing complete Text Messaging application.