Python Chat Application
In this article, we will create a chat program by using python socket programming and Multi-Threading.
🔅 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.
- We need two systems. Both will act as client and server.
- As it's a python program, we need a python interpreter to run it.
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.
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 firstname.lastname@example.org:rohitraut3366/Chat-Application-Using-Socket-Programming-in-python.git
Step 2: Check the IP address of both systems
Step 3: Code
here we need two modules socket and threading.
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 has a Thread function that takes the name of the function as a target. Help to run two functionality in parallel.