Skip to content

Instantly share code, notes, and snippets.

@jpignata
Last active May 18, 2019 01:22
Show Gist options
  • Save jpignata/366582c0c89c28cefd8b0646d4842188 to your computer and use it in GitHub Desktop.
Save jpignata/366582c0c89c28cefd8b0646d4842188 to your computer and use it in GitHub Desktop.
import threading
import socket
CHARS = [chr(i).encode('ascii') for i in range(32, 127)]
NEWLINE = '\n'.encode('ascii')
def server(host='127.0.0.1', port=19):
def generate(client):
line = 1
while True:
try:
for i in range(72):
char = CHARS[(line + i) % len(CHARS)]
client.send(char)
client.send(NEWLINE)
except Exception:
client.close()
break
line += 1
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((host, port))
sock.listen()
while True:
client, _ = sock.accept()
thread = threading.Thread(target=generate, args=(client,))
thread.start()
server()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment