Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import socket
- import os
- import signal
- import time
- import random
- # Open a socket.
- server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- server_socket.bind(("", 8080))
- server_socket.listen(128)
- # For keeping track of child process pids.
- N = 1
- wpids = []
- for _ in range(N):
- wpid = os.fork()
- wpids.append(wpid)
- if wpid == 0:
- while True:
- connection, address = server_socket.accept()
- print (connection.recv (1024).decode())
- time.sleep(random.randint(1,3))
- connection.send("HTTP/1.1 200 OK\n".encode()); ????
- connection.send("Content-length: 46\n".encode()); ?????
- connection.send("Content-Type: text/html\n\n".encode()); ?????
- connection.send("<html><body><H1>Hello world</H1></body></html>".encode()); ??????????
- connection.close()
- # Forward any relevant signals to the child processes.
- def handler(signum, frame):
- for wpid in wpids:
- os.kill(wpid, signum)
- signal.signal(signal.SIGINT, handler)
- signal.signal(signal.SIGQUIT, handler)
- for _ in range(N):
- os.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement