-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchat_module.py
More file actions
46 lines (36 loc) · 778 Bytes
/
chat_module.py
File metadata and controls
46 lines (36 loc) · 778 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
import socket
import pyfiglet
import threading
import os
import subprocess as sp
from colorama import Fore,Style
os.system("clear")
def chat():
afm=socket.AF_INET
protocol=socket.SOCK_DGRAM
ip="192.168.29.203"
port_number=1234
s=socket.socket(afm,protocol)
s.bind((ip,port_number))
os.system("tput reset")
print(pyfiglet.figlet_format("Chat App"))
def recv():
while True:
x=s.recvfrom(1024)
ip=x[1][0]
msg=x[0].decode()
print(Fore.BLUE)
print((msg+" from "+ip).rjust(50,'-'))
print(Style.RESET_ALL)
def send():
while True:
x=input()
if x=="exit":
break
else:
s.sendto(x.encode(),('192.168.29.178',2224))
x1=threading.Thread(target=recv)
x2=threading.Thread(target=send)
x1.start()
x2.start()
input()