#!/usr/bin/env python3 import socket import json import time def create_udp_client(): # Create UDP socket client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Server address and port server_address = ('localhost', 9021) try: # Sample JSON data to send json_data = { "camera_id": 5, "shutter_speed": 0.001 } # Convert JSON to string json_string = json.dumps(json_data, indent=2) print("Sending JSON data:") print(json_string) print(f"\nSending to {server_address[0]}:{server_address[1]}") # Send JSON data as bytes client_socket.sendto(json_string.encode('utf-8'), server_address) print("Data sent successfully!") except Exception as e: print(f"Error occurred: {e}") finally: # Close the socket client_socket.close() if __name__ == "__main__": create_udp_client()