-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
110 lines (72 loc) · 2.2 KB
/
server.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import socket
from termcolor import cprint,colored
import threading
import sys
import platform
import os
import time
if platform.system() == "Windows":
clear = lambda:os.system("cls")
if platform.system() == "Linux":
clear = lambda:os.system("clear")
cprint("[!] Enter your Profile name: ","green",end="")
name = input()
s = socket.socket()
s.bind(("",80))
# cprint('Waiting For Connection','white','on_green',["blink"])
cprint('Waiting For Connection',"blue")
s.listen(5)
session,addr = s.accept()
cprint("[*] Incomming Connection","white","on_green")
time.sleep(2)
clear()
cprint("Connection Established\n","white","on_cyan",["blink"])
cprint("Chat Program Activated ! Profile name %s\n"%(name),"white","on_yellow",["bold"])
cprint('[NOTE] Type "Bye" or "Exit" to quit Chat Program\n',"green")
session.send(name.encode())
partner = session.recv(1024).decode("utf-8")
outing = partner+" ---> Bye"
cprint("Emoji's You Like","white")
print("""
😀 😁 😂 🤣 😃 😄 😅 😆 😉 😊 😋 😎 😍 😘 🥰 😗
😙 😚 ☺️ 🙂 🤗 🥴 🤩 🤔 🤨 😐 😑 😶 🙄 😏 😣 😥
😮 🤐 😯 😪 😫 😴 😌 😛 😜 😝 😒 🤭 🥵 🥶 😳 🤪
😵 😡 😠 🤬 😷 🤒 🤕 🤢 🤮 🤧 😇 🤠 🤡 🥳 😓 😔
🥴 🤪 😕 🙃 🤑 😲 ☹️ 🙁 😖 😞 😟 😤 😢 😭 😦 😧
😨 😩 🤯 😬 😰 😱 🥳 😵 😈 👹 👺 💀 👻 👽 🤖 💩
""")
def sending():
try:
while True:
#sending
msg = input()
if msg == "Exit" or msg == "exit" or msg == "bye" or msg == "Bye":
msg = name+" ---> Bye"
session.send(msg.encode())
cprint("\nConnection Closed","white","on_red",["blink"])
break
msg = "[+] "+name+" --> "+msg
session.send(msg.encode())
msg = ''
session.close()
sys.exit()
except:
sys.exit()
def receving():
try:
while True:
#recving
text = session.recv(1024).decode("utf-8")
if outing == text:
print(text)
cprint("\nConnection Closed","white","on_red",["blink"])
break
cprint(text,"magenta")
session.close()
sys.exit()
except:
sys.exit()
t1 = threading.Thread(target=sending)
t2 = threading.Thread(target=receving)
t1.start()
t2.start()