1

I've got a very simple set up in Pure Data: it creates a local host socket and sends a number through this socket. The number comes either from a Vslider or a Number box.

Pure Data

This data is then received in Python through the Socket module. It is decoded and converted to float(), thereafter the float value is printed.

import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 13001)
sock.bind(server_address)
sock.listen(1)

while True:
    connection, client_address = sock.accept()

    try:
        while True:
            data = connection.recv(16)
            data = data.decode("utf-8")
            data = data.replace('\n', '').replace('\t', '').replace('\r', '').replace(';', '')
            VARIABLE = float(data)
            print(f'received {VARIABLE} as a float')
    finally:
        connection.close()

The problem is that when I move the Vslider too quickly (or when I move the mouse cursor in the number box too quickly). The number values sent from Pd are "appended" together. For instance, I go very quickly from 1 to 10. Values 1-6 are correctly decoded and printed. However, values 7-10 are not printed separately, instead being printed as 78910. This can happen with any values up to 10 numbers or so. So I could get 12345678910111213 and so on. I'm fairly new to Pd so I'm not sure at all where this error originated.

python output

OndBoc
  • 9
  • 2

0 Answers0