Building Chat Application using Socket Programming in Python

Ritesh Singh
2 min readFeb 18, 2021

Problem Statement:

  • Create your own Chat Servers, and establish a network to transfer data using Socket Programing by creating both Server and Client machine as Sender and Receiver both. Do this program using UDP data transfer protocol.
  • Use multi-threading concept to get and receive data parallelly from both the Server Sides. Observe the challenges that you face to achieve this using UDP.

For this Problem Statement, we need two OS πŸ˜….

Python Code:

Explanation:

First, we need to import socket(for socket programming) and threading(for Multi Thread programming). After that, I have used AF_NET(for IPv4) and SOCK_DGRAM(for UDP). After this Now we need System IP and Port and Client IP and Port. I have made two functions one for the sender and one for the receiver. sendto(for sending msg) and recvfrom(for receiving msg).Final step, use threading concepts to runs these functions in parallelism πŸš€.

Output

Linux OS
Windows OS

Note: This program is based on UDP Protocol, if u connect more than 1 client the messages will be messed up πŸ˜•. For solving this issue use TCP πŸ˜ƒ .

Source Code:

--

--