Created
October 17, 2018 05:40
-
-
Save Bogdanp/45e1a491007ad72ad400701d6edbeb3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with socket.socket() as server_sock: | |
server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
server_sock.bind((HOST, PORT)) | |
server_sock.listen(0) | |
print(f"Listening on {HOST}:{PORT}...") | |
while True: | |
client_sock, client_addr = server_sock.accept() | |
print(f"New connection from {client_addr}.") | |
with client_sock: | |
for request_line in iter_lines(client_sock): | |
print(request_line) | |
client_sock.sendall(RESPONSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment