Created
March 31, 2022 21:55
-
-
Save ltpitt/caff97b137d7e6f9ad1e7b9c5d15569c to your computer and use it in GitHub Desktop.
A very basic telnet server in Python to communicate via Telnet with a Commodore 64
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
#!/usr/bin/env python3 | |
import socket | |
# Connect to the server with `telnet $HOSTNAME 5000`. | |
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
server.setblocking(False) | |
server.bind((socket.gethostname(), 5000)) | |
server.listen(5) | |
connections = [] | |
while True: | |
try: | |
connection, address = server.accept() | |
connection.setblocking(False) | |
connections.append(connection) | |
except BlockingIOError: | |
pass | |
for connection in connections: | |
try: | |
message = connection.recv(4096) | |
for connection in connections: | |
if "commodore".encode() in message: | |
connection.send("Hello, dear C64!\n".encode()) | |
elif "quit".encode() in message: | |
exit() | |
else: | |
connection.send("Which is the magic word?\n".encode()) | |
except BlockingIOError: | |
continue | |
except BrokenPipeError: | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment