import socket import math import time IP = "192.168.1.201" PORT = 6000 def get_integer_and_fractional_parts(number): integer_fractional = str(abs(number)).split('.') return list(map(int, integer_fractional)) def pad_number(number): integer_part, fractional_part = get_integer_and_fractional_parts(number) pad_length = 6 integer_part = str(integer_part)[:pad_length].rjust(pad_length, '0') fractional_part = str(fractional_part)[:pad_length].ljust(pad_length, '0') prefix = "+" if number < 0: prefix = "-" return (f"{prefix}{integer_part}.{fractional_part}", 2 + pad_length * 2) with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: sock.connect((IP, PORT)) # data = sock.recv(1024) # print(data) while True: t = time.time() frequency = 0.1 target = 1 * math.sin(frequency * 2.0 * math.pi * t) for i in range(6): padded, _ = pad_number(target) print(padded) message = padded.encode('utf-8') sock.sendall(message) time.sleep(0.05)