-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
49 lines (36 loc) · 1.55 KB
/
Copy pathserver.py
File metadata and controls
49 lines (36 loc) · 1.55 KB
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
import socket
import signal
import sys
from colorama import Fore, Back, Style
server = socket.socket()
host = socket.gethostname()
username = host.capitalize()
print(Fore.MAGENTA + 'Host adresiniz:', Style.BRIGHT + Back.MAGENTA + Fore.WHITE + host + Style.RESET_ALL)
port = 8080
server.bind((host, port))
print(Fore.LIGHTYELLOW_EX + 'Bağlantı için bekleniliyor..' + Style.RESET_ALL)
server.listen(5) # 5 bağlantı kabul edilebilir
print(Fore.GREEN + 'Bağlantılar kabul edilebilir..' + Style.RESET_ALL)
conn, addr = server.accept()
print(Fore.GREEN + str(addr[0]), Fore.RESET + ':', Fore.GREEN + str(addr[1]), Fore.LIGHTGREEN_EX + ' sunucuya bağlandı\n' + Style.RESET_ALL)
while True:
message = input(Fore.YELLOW + '[Sen] > ' + Fore.RESET)
message = message.encode()
conn.send(message)
while True:
incoming_message = conn.recv(1024).decode()
if not incoming_message:
break
print(Fore.CYAN + '[' + str(addr[0]) + '] : ' + incoming_message + Style.RESET_ALL)
message = input(Fore.YELLOW + '[Sen] > ' + Fore.RESET)
message = message.encode()
conn.send(message)
conn.close()
print(Fore.RED + 'Bağlantı kesildi.. Bekleniyor..' + Style.RESET_ALL)
conn, addr = server.accept()
print(Fore.GREEN + str(addr[0]), Fore.RESET + ':', Fore.GREEN + str(addr[1]), Fore.LIGHTGREEN_EX + ' sunucuya bağlandı\n' + Style.RESET_ALL)
def signal_handler(sig, frame):
print('Program sonlandırılıyor...')
server.close()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)