Python Chat Application

Socket Programming using Python

Rohit Raut
3 min readApr 18, 2021
From Google

In this article, we will create a chat program by using python socket programming and Multi-Threading.

Task Description:

🔅 Create your own Chat UDP Servers, and establish a network to transfer data using Socket Programing by creating both Server and Client machines as Sender and Receiver both.

🔅 Use multi-threading concept to get and receive data parallelly from both the Server Sides.

Prerequisite

  1. We need two systems. Both will act as client and server.
  2. As it's a python program, we need a python interpreter to run it.

Socket Programming

IP with the port number is known as a socket. It is used for bi-directional communication between two systems. This communication is done via ports that we attached while creating the socket program.

Multi-Threading

A thread is a sub-process that runs a set task independent of others. So every time a user connects to some server, the server creates a thread for the request.

Let's start with the implementation

Step 1: Download the code from the repository in both the system

git clone git@github.com:rohitraut3366/Chat-Application-Using-Socket-Programming-in-python.git

Step 2: Check the IP address of both systems

CMD: ifconfig

Step 3: Code

here we need two modules socket and threading.

socket:

The socket has a socket function that helps us to define the type of protocol and type of IP.

socket.SOCK_DGRAM --> used to defind UDP protocol
socket.AF_INET--> There are multiple IP address families eg IPV4, IPV6. AF_INET is used to set IPV4.
send_to --> used to send data to ipPort[tuple having (address,port)]

Threading

Threading has a Thread function that takes the name of the function as a target. Help to run two functionality in parallel.

Step 4: Run the code and follow the instructions.

Now our chat server has been created. That’s all for this article.

follow me for the more interesting technological articles.

Thank you for reading….:)

--

--