Chat Program using UDP with and without multi-threading

ARTH β Task 17 π¨π»βπ»
Task Descriptionπ
π -17.1 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.
π -17.2 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.
Task 1 :- Creating Chat Servers via UDP Protocol
So I created a Server and Client using Socket Programming and got the output as follows :-
Server Side :-

Client Side :-

Task 2 :- Using Multi-threading to achieve itβ¦
While in Multi-threading, the code will be a bit different as we will use threading module, which will help read and send message at the same time. The overall output will be similar but the code will be different.
β import socket
import threading
import os
import time
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
print(β β β β β β β β β β β β β β β β β β β β β β \nβ)
print(β\t\tChat Application using multithreadingβ)
print(β β β β β β β β β β β β β β β β β β β β β β \nβ) print(βHiiβ¦. This is WINDOWS10\nβ)
ip = input(β\n\t\tEnter Your IP : β)
port =int(input(β\n\tEnter your port number :β))
clientip = input(β\n\t\tEnter Sender IP : β)
clientport =int(input(β\n\tEnter sender port number :β))
s.bind( (ip,port) )
def send():
while True:
msg = input(βYour Message: β).encode() s.sendto(msg,(clientip,clientport)) if msg.decode() == βexitβ or msg.decode() == βquitβ: os._exit(1)
def recv():
while True:
msg = s.recvfrom(1024) if msg[0].decode() == βquitβ or msg[0].decode() == βexitβ: os._exit(1) print(β\n\t\t\t\t\t\tReceived Msg: β+ msg[0].decode())
t1 = threading.Thread(target=recv)
t2 = threading.Thread(target=send)
t1.start()
t2.start() β
So, this is the Threading code and it will help execute multi-threading in a program.