-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwindows.py
48 lines (38 loc) · 976 Bytes
/
windows.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
os.system("cls")
os.system("color 6")
from pyfiglet import Figlet
f = Figlet(font="puffy")
a = f.renderText("UDP CHAT APP")
print(a)
# importing required modules...
import socket
import threading
# AF_INET = Network Address Family : ipv4
# SOCK_DGRAM = DataGram Socket : UDP
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# System IP
ip = "Ip of the System"
port = 2222
# Reciever IP
sendip = input("\n\t\tEnter Reciever IP : ")
sendport = 1111
# Binding system IP and port
s.bind((ip, port))
# Function for sending message
def send():
while True:
x = input("")
s.sendto(x.encode(), (sendip, sendport))
if (("bye" in x) or ("exit" in x)):
os._exit(1)
# Function for recieving message
def recieve():
while True:
x = s.recvfrom(1024)
print("\n\t\t\t" + "{} : ".format(sendip) + x[0].decode())
# Applying Multi-Threading
send = threading.Thread( target=send )
recieve = threading.Thread( target=recieve )
send.start()
recieve.start()