I want to be able to connect from my Commodore 64 (that has a "wifi modem") to a Linux Raspberry Pi.
The ideal solution would be something like ssh or http clearly but the best I could find is telnet via CCGMS on C64 and write a little python script on the Raspberry side:
#!/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
This small example works just fine if I connect from another Raspberry Pi. If I connect form the Commodore 64 I can read data that is sent from the Raspberry but I cannot send data from the C64 to the Raspberry. Each time I type a character the Raspberry immediately asks again "Which is the magic word?"
I'd be glad to understand what am I doing wrong and/or receive a better solution to allow the C64 to communicate with the Raspberry Pi.