-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
35 lines (29 loc) · 851 Bytes
/
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
from threading import *
from requirement import *
from socket import *
import random
import datetime
HOST = "127.0.0.1"
PORT = random.randint(12000, 14999)
CLIENTS = []
THREADS = []
def service(conn, address, number):
request = conn.recv(1024).decode()
if(request != ""):
response, _, _ = response_to_request(request)
conn.send(response)
print('Response sent Successfully')
conn.close()
s = socket(AF_INET, SOCK_STREAM) # Creating a socket
s.bind((HOST, PORT)) # Binding that socket
s.listen(5) # listening on that socket
print("Listening at ", s.getsockname()) # Printing the socket
count = 0
while True:
try:
conn, addr = s.accept()
print(conn, addr)
service(conn, addr, 0)
except KeyboardInterrupt:
break
s.close()