Here is an example of creating a real time chatting application using python, web sockets and tkinter gui. This basic chat application provides an overview of socket programming using to demonstrate a client server architecture where multiple clients connect to the server and chat with random persons online
- Allows one-to-one communication with the clients online
- Allows broadcasting messages to all the clients online
This application is compatible with python version 3 and above
Below are the modules used
- threading --> It enables the client to constantly receive the messages from server and server to keep accepting new connections and redirecting the messages from existing messages
- socket --> Allows the client and server to communicate with each other
- tkinter --> GUI for python, its already included in the python
- time --> Mainly it enables to maintain the speed of sending and receiving the data between the server and client
[!Note]:
There is no requirement to download any additional modules
Below is the GUI of server side application
- Firstly, the server admin needs to enter the IP address to which server will bind and run on that IP and port number is by default 9000
- Hit Run Server button to run the server
- The white blank space is the place where server displays the client who has connected and disconnected to the server
- The Stop Server button stops the server
Below is the GUI of the client side application
- The client first need to enter the IP address of the server and enter their username which must unique among all the currently connected clients otherwise a warning pop up is displayed saying Username Exists
- The Online clients workspace is the place where name of the currently online clients to server are displayed, and client can select the particular client useing select button with whome they want to chat
- Chat with your friends is the workspace where private chat between two clients are shown
- Send button sends the message privately to the user with whom the client is chatting
- Broadcast workspace allows to display the broadcasted messages
- Broadcast button sends messages to all the clients currently online
- First, run Server.py and run server
- Then, run multiple App.py with different usernames and connect to the server
- Now, start messaging or communicating to the selected client
Basically, each of the client gets connected to the server with their socket, each clients socket is associated with their unique username and stored at run time to identify whose message is to be redirected to which user/client. Each message from the client is a string where in the starting of the actual message receiver's username and sender's username is added and decoded at the server. This collection of a string having receiver + sender + message is then divided in two parts receiver & server + message to identify the reciever where this remaining message is to be redirected. If the receiver is online the message is redirected to the respective client otherwise nothing happens. If a client broadcasts a message, the server redirects the message to all the clients online.
- Group chatting can be established
- Sharing of mutlimedia files can be added

