-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
35 lines (27 loc) · 794 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
from socket import *
def createServer():
servsock=socket(AF_INET,SOCK_STREAM)
try:
servsock.bind(('localhost',9000))
servsock.listen(5)
while(1):
(clisock,addrs)=servsock.accept()
rd=clisock.recv(5000).decode()
chunks=rd.split('\n')
if len(chunks)>0:
print(chunks[0])
data='HTTP/1.1 200 OK\r\n'
data+='ContentType:HTML/TEXT; '
data+='Charset:utf-8\r\n\r\n'
data+='<html><body><center><h1>HELLO WORLD</h1></center></body></html>\r\n\r\n'
clisock.sendall(data.encode())
clisock.shutdown(SHUT_WR)
except KeyboardInterrupt:
print('KeyboardInterrupt: shutting server down...')
except Exception as e:
print('Error')
print(e)
servsock.close()
if __name__=='__main__':
print('Server started Access to https://localhost:9000')
createServer()