-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat1.py
More file actions
48 lines (35 loc) · 916 Bytes
/
chat1.py
File metadata and controls
48 lines (35 loc) · 916 Bytes
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 socket
import threading
import os
import sys
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
os.system("tput setaf 11")
ip = input("\n\t\tEnter Your IP : ")
port = 1234
s.bind( (ip,port) )
sip = input("\n\t\tEnter Server IP : ")
sport = 1234
print()
os.system('clear')
os.system('tput setaf 222')
os.system('figlet UdP cHaT aPp')
def send():
while True:
os.system('tput setaf 46')
msg = input('\n').encode()
s.sendto(msg,(sip,sport))
if msg.decode() == "exit":
os.system('tput setaf 7')
os._exit(1)
def recv():
while True:
os.system('tput setaf 51')
print('')
msg = s.recvfrom(1024)
if msg[0].decode() == "exit":
os._exit(1)
print('\n\t\t\t\t :^=^: ' + msg[0].decode())
t1 = threading.Thread(target=send)
t2 = threading.Thread(target=recv)
t1.start()
t2.start()