Question: java code 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
java code

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. The application is implemented using a module named "p2pchat" The application uses TCP as the transport protocol. The p2pchat module works as both client and server using multithreading to allow for sending and receiving at the same time. When the p2pchat module starts using the command "p2pchat" i.e. without command-line 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. If the module starts using the command "2pchat [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. 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. 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. Developing a graphical user interface for the program is optional, provided that all the specifications above are fulfilled
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
