Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- def start_server():
- try:
- server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- server.bind(('124.0.8.23',2957))
- server.listen(100000)
- while True:
- print('Working, please wait...')
- client_socket, address = server.accept()
- data = client_socket.recv(100000).decode('utf-8')
- # print(data)
- content = load_page_request(data)
- client_socket.send(content)
- client_socket.shutdown(socket.SHUT_WR)
- except KeyboardInterrupt:
- server.close()
- def load_page_request(request_file):
- HDRS = 'HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nConnect-RayId: ComputerIPAddress:ComputerPort;\r\n\r\n'
- HDRS_404 = 'HTTP/1.1 404 OK\r\nContent-Type: text/html; charset=utf-8\r\nConnect-RayId: ComputerIPAddress:ComputerPort;\r\n\r\n'
- path = request_file.split(' ')[1]
- response = ''
- try:
- with open('views'+path, 'rb') as file:
- response = file.read()
- return HDRS.encode('utf-8')
- except FileNotFoundError:
- return (HDRS_404 + 'Nginx ERROR: 404 WebSite Not Found').encode('utf-8')
- client_socket2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM )
- if __name__ == '__main__':
- start_server()
Advertisement
Comments
-
- A my functionaly python server
-
- for start my python server enter command -> python3 server.py
Add Comment
Please, Sign In to add comment
Advertisement