PY
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
"""
very simple
HTTP and HTTPS server created by SHAIL from scratch
using socket
"""
from socket import socket, error, SOCK_STREAM, AF_INET
import ssl
def connect(port, host="", prot="HTTP"):
if prot == "HTTPS":
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain('cert/localhost.crt', 'cert/localhost.key') # Path to key and certificate to be used for encryption
sock = socket(AF_INET, SOCK_STREAM, 0)
sock.bind((host, port))
sock.listen(5)
if prot == "HTTPS":
server = context.wrap_socket(sock, server_side=True)
else:
server = sock
print("%s : Listening %d" % (prot, port))
accept_conn(server)
def accept_conn(server):
while True:
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run