24 lines
651 B
Python
24 lines
651 B
Python
import socket
|
|
|
|
PORT = 8081
|
|
HOST = '0.0.0.0'
|
|
|
|
def http_server():
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server:
|
|
server.bind((HOST, PORT))
|
|
print(f"Server running on {HOST}:{PORT}")
|
|
|
|
server.listen()
|
|
|
|
while True:
|
|
conn, addr = server.accept()
|
|
with conn:
|
|
print('Connected by', addr)
|
|
request = conn.recv(1024)
|
|
print('Request:', request.decode('utf-8'))
|
|
|
|
response = b'HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\nHello, world'
|
|
conn.sendall(response)
|
|
|
|
if __name__ == '__main__':
|
|
http_server() |