shobhit6993 / P2P-chat-application

A simple P2P chat in Linux.
10 stars 3 forks source link

To run server

g++ -std=c++11 server.cpp -lpthread -o server

./server

To run client

g++ -std=c++11 -fpermissive -w client.cpp -lpthread -o client

./client 10.0.3.41 stdin

or ./client 10.0.3.41 file

NOTE: the argument to ./client is the IP address of the server.


IMPORTANT NOTE:

Different clients CANNOT be on the same machine. They MUST be on different machines with different IPs for the chat application to function. However, the server, and one of the clients can be on the same machine, in which case that client will be run by command ./client 127.0.0.1 file or ./client 127.0.0.1 stdin


if stdin argument is used, chat will show on terminal although formatting might be bad if file argument is used, the chat is saved in chat.txt. Messages from peer are not shown on the terminal


If you are using the file mode for clients, then use the following tail command in a new terminal which shows the contents of the file in incremental fashion, as and when it is updated.

tail -f chat.txt


SAMPLE OUTPUT IN CHAT

ME#1:sho1

            MSG:1 seen.

    PEER#1:har1

    PEER#2:har2

ME#2:sho2

            MSG:2 seen.

ME means the client itself and PEER means the Peer with whom he/she is chatting. #1 denotes the message no. (to verify seen status of that message). While chatting sending a /exit message closes the connection and terminates the application.

In file mode, you will only see the messages you enter and not the received ones (on terminal). However, messages are always received and sent synchronously. They are not displayed on terminal, rather dumped into file so that the order of message and acknowledgment (MSG: seen thing) delivery can been shown to be correct. On terminal, if user was entering some message, while a reply was being received, then the user's message will flow above in the terminal, leading to confusion and give a "not so comforting" experience.

FOR TERMINATING EITHER SERVER OR CLIENT PREMATURELY

Use CTRL + C, not CTRL + Z, as the latter could leave ports still bound, impeding re-execution of server or client.