Created
October 17, 2018 05:36
-
-
Save Bogdanp/6e0927e9a6c833676dd712ea789b7f2f 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
import socket | |
HOST = "127.0.0.1" | |
PORT = 9000 | |
# By default, socket.socket creates TCP sockets. | |
with socket.socket() as server_sock: | |
# This tells the kernel to reuse sockets that are in `TIME_WAIT` state. | |
server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
# This tells the socket what address to bind to. | |
server_sock.bind((HOST, PORT)) | |
# 0 is the number of pending connections the socket may have before | |
# new connections are refused. Since this server is going to process | |
# one connection at a time, we want to refuse any additional connections. | |
server_sock.listen(0) | |
print(f"Listening on {HOST}:{PORT}...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment