-
Notifications
You must be signed in to change notification settings - Fork 39
/
main.py
31 lines (25 loc) Β· 908 Bytes
/
main.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
from socket import *
def createServer():
serversocket = socket(AF_INET, SOCK_STREAM)
try:
serversocket.bind(('localhost', 9000))
serversocket.listen(5)
while(1):
(clientsocket, address) = serversocket.accept()
rd = clientsocket.recv(5000).decode()
pieces = rd.split("\n")
if(len(pieces) > 0): print(pieces[0])
data = "HTTP/1.1 200 OK\r\n"
data += "Content-type: text/html; charset=utf-8\r\n"
data += "\r\n"
data += "<html><body>Hello World</body></html>\r\n\r\n"
clientsocket.sendall(data.encode())
clientsocket.shutdown(SHUT_WR)
except KeyboardInterrupt:
print("\nShutting down...\n")
except Exception as exc:
print("Error:\n");
print(exc)
serversocket.close()
print('Access http://localhost:9000')
createServer()