-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlinux.py
56 lines (42 loc) · 1.1 KB
/
linux.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
49
50
51
52
53
54
55
import os
os.system("clear")
from pyfiglet import Figlet
f = Figlet(font='puffy')
a = f.renderText("UDP CHAT APP")
os.system("tput setaf 3")
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 "
port = 1111
# Reciever IP
os.system("tput setaf 6")
sendip = input("\n\t\tEnter Reciever IP: ")
sendport = 2222
os.system("tput setaf 7")
# Binding system IP and port
s.bind((ip, port))
os.system("tput setaf 2")
# Function for recieving message
def recieve():
while True:
x = s.recvfrom(1024)
print("\n\t\t\t" + "{} : ".format(sendip) + x[0].decode())
# 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.system("tput setaf 7")
os._exit(1)
# Applying Multi-Threading
recieve = threading.Thread( target=recieve )
send = threading.Thread( target=send )
recieve.start()
send.start()