Create simple Chatting Program using python socket module

Posted by Suraj Singh on January 12, 2017 · 9 mins read

Hello readers,

            Today I Gonna to show you how to create Real-time chatting program with GUI (Graphical User Interface) using python? Or How To create chatting client and server using python socket, Tkinter and threading module? Or How to create Messaging Program using python example? Etc..

Here, I Created a GUI chat program written in python2.7. It is designed to not need a central server and so work very well on LANs that are not connected to the internet. One user starts the program in server mode, listening on a port of their choosing, and then other users will use client mode to connect to their machine. Each new user then acts as a host, allowing other people to connect to them. 

Here this is an Screenshot captured on Ubuntu

So, what is chat server?

The server is like a middle man among clients. It can queue up to 10 clients. The server broadcasts any messages from a client to the other participants. So, the server provides a sort of chatting room.

The chat server does the following things
1. Accept multiple incoming connections for client.
2. Read incoming messages from each client and broadcast them to all other connected clients.

Now, what is chat client?
client is another important part of connections.
It connects to a remote server, sends messages and receives messages.

The chat client does the following 2 things :
1. Listen for incoming messages from the server.
2. Check user input. If the user types in a message then send it to the server

Features of program:
1. Cross-Platform Support
2. Easy To Use
3. Easy To Maintain
4. Good Example Of Socket Prgramming
5. With GUI Its Looks very Simple
6. Light weight
7. etc..etc

Requirements For This Scripts are
1. python Enviroment
2. Modules:
socket, threading, Tkinter Only

In This Script, I tried to write code that are compitable with python2.7 and python 3.5 also.

For Using This Program, First of all download code link given below then extract them on a
folder then open scripts names

Then You will see an Small Dialog window asking for server or client mode.

For chatting one user have to select server mode and another user have to select client mode.

If You are using server mode then you have to give your ip address to client mode user for creating an connection between you.

And if You are using client mode: when you will start script on client mode. An dialog box automatically raised and it will ask you about server ip address. Here entered the ip address
of server mode user.

Then click on Connect button and then wait for connection
if script found any connection. Status button will automatically changed in green color and
now you are ready for chatting.


For More Good Example check this
or Google it.

For Download click here:

WARNING: This code is just a simple demo showing how to use socket in Python Socket module with Tkinter and threading module. it is NOT a complete project that’s why it has many bugs. If you'd like to implement a real chatroom, you should find some other open source projects.

Thanks For Support
Please, Feel Free To Leave A Comment If Our Article has Helped You.