Question: Write an application using Java or C++ programming language to implement a simple command line peer-to-peer chat system through socket programming, and multi-threading using the

Write an application using Java or C++ programming language to implement a simple command line peer-to-peer chat system through socket programming, and multi-threading using the following specifications.

1. The application is implemented using a module named p2pchat

2. The application uses TCP as the transport protocol.

3. The p2pchat module works as both client and server using multithreading to allow for sending and receiving at the same time.

4. When the p2pchat module starts using the command p2pchat i.e. without commandline parameters, it listens on port 5789 for incoming connections. If it receives a connection request, it accepts the connection, and opens a (separate sending thread) to wait for the user input to send to the other peer-to-peer chat program, while listens to the incoming text on the main program thread.

5. If the module starts using the command p2pchat [ip-address], it initiates a connection with another p2pchat with the IP address given in the [ip-address] command-line parameter. It then opens a (separate sending thread) that waits for the user input text to be sent to the other peer-to-peer chat program, while listens to the incoming text on the main program thread.

6. Text chat: when the user writes a non-command text (i.e. any text that does not start with the word sendfile) on any p2pchat peer and presses enter, the text message appears on the other p2pchat peer window.

7. Send the content of a small text file: If the user writes a text that starts with sendfile [filename and location], the sending thread will read the content of the file highlighted by the [filename and location] and send the content of the file to the other peer-to-peer chat program.

8. Developing a graphical user interface for the program is optional, provided that all the specifications above are fulfilled. Warning: the source code of the program will be cross-checked for similarity. Test cases:

1- Description: start the module for the first time with no command-line parameters o On the command line: > p2pchat o Expected output: waiting for the other peer program..

2- Description: start the module for the second or third time with no command-line parameters o On the command line: > p2pchat o Expected output: Error: port in use

3- Description: start the module for the first time with the IP of the other peer program o On the command line: > p2pchat [ip address of the other peer] o Expected output: connection established on both peer programs, and waiting for user text.

4- Description: start the module for the second or third time with the IP of the other peer program o On the command line: > p2pchat [ip address of the other peer] o Expected output: Error: connection cannot be established

5- Description: text chatting Computer engineering program- Spring, 2017 Page 3 of 3 o while the module is started and connection is established, write user input text e.g. Hello, this is amr o Expected output: the exact message is displayed on the other peer program

6- Description: repeat test 5 on different sides repeatedly any arbitrary order o while the module is started and connection is established, write non-command user input text o Expected output: the exact message is displayed on the other peer program every time the user enters a text on either side of the programs.

7- Description: send a small text file that does not exist in the same directory o while the module is started and connection is established, write a command user input text send [filename and location]

(note: the file does not exist in this location) o expected output: file does not exist

8- Description: send a small text file that exists in the same o While the module is started and connection is established, write a command user input text sendfile [filename and location]. Suggested text file content:

textfile.txt

============================

Assalamo Alaikom I hope this message finds you well, and everything is going fine. Looking forward to meeting you in the near future. Regards, End of text

============================

Expected output: the content of the text file will display on the other peer program.

9- Description: repeat test case 7 on the other peer program o Expected output: same error message that the file does not exist.

10- Description: Repeat test case 8 on the other peer program o Expected output: the content of the text file will display on the other peer program.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!