server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # enable address reuse
server.bind((HOST, PORT))
server.listen(5)
print(f"RSHELL Server is running on {HOST}:{PORT}")By calling setsockopt() on the socket object with the SO_REUSEADDR option, you are telling the operating system to allow the reuse of the same address. This should help you avoid the Address already in use error when restarting your server.