1. import json
  2. import time
  3. import threading
  4. import socket
  5. def get_config_values():
  6. """Simulates fetching configuration values from an isolated environment."""
  7. # Replace with actual logic to retrieve config values
  8. config = {
  9. "database_host": "localhost",
  10. "database_port": 5432,
  11. "api_key": "your_api_key",
  12. "log_level": "INFO"
  13. }
  14. return config
  15. def stream_config(host, port):
  16. """Streams configuration values to a client."""
  17. try:
  18. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
  19. s.bind((host, port))
  20. s.listen()
  21. print(f"Listening on {host}:{port}")
  22. conn, addr = s.accept()
  23. print(f"Connected by {addr}")
  24. while True:
  25. config = get_config_values()
  26. json_config = json.dumps(config)
  27. conn.sendall(json_config.encode()) # Send JSON data
  28. time.sleep(5) # Send config every 5 seconds
  29. except Exception as e:
  30. print(f"Error streaming config: {e}")
  31. if __name__ == "__main__":
  32. HOST = "localhost" # Replace with desired host
  33. PORT = 65432 # Replace with desired port
  34. stream_config(HOST, PORT)

Add your comment