Building Chat Application using Socket Programming in Python

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:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store