Hi. I've been trying to mess around with netsend to send information to a Python program, but have met with no success. From reading previous posts, it seems like there might be some functionality, but then, not really.
Can anyone clarify? So far, when trying to use a basic TCP socket, I've just gotten:

connecting to port 3000
net: 1
pd-to-gui socket: Broken pipe
Underrun detected: 4 blocks dropped
Makefile:502: recipe for target 'runide' failed
make: *** [runide] Error 1
Bela stopped 

If there is no functional version of netsend, can anyone suggest a way to send floats from Pd to Python on the Bela? In the past, I've had the two communicate just by turning GPIO pins on and off, but I actually need now to have Python read floats and am therefore at a loss.

Thanks,
Colin

this patch works for me with the libpd you get with the latest image :

alt text

However, you need to add the following line at the very top of Bela/core/default_libpd_render.cpp:

#define PD_THREADED_IO

    Awesome! Thanks! I'll give it a shot.

    By "default in master," do you mean that an update to Bela makes this default?

    Hi Giulio,

    What address are you using on the Python end of things? I've tried a couple different setups, but nothing seems to connect and Bela keeps stopping. My Python is just this:

    import socket
    
    TCP_IP = '192.168.1.90' #IP of Bela via wifi
    TCP_PORT = 3000
    BUFFER_SIZE = 20
    
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((TCP_IP, TCP_PORT))
    s.listen(1)
    
    conn, addr = s.accept()
    print ("connection addr: ", addr)
    
    while 1:
        data = s.recv(BUFFER_SIZE)
        if not data: break
        print ("received: " , data)
    
    conn.close()

    But I've also tried 'localhost' and '192.168.7.1' - with matching IP's in Pd of course. For some reason, I can't get the connection to work.

    I keep getting this in the IDE:

    connecting to port 8000
    pd-to-gui socket: Broken pipe
    Makefile:504: recipe for target 'runide' failed
    make: *** [runide] Error 1Bela stopped

    And this from Python:

    root@bela:~/Robut# python netreceive.py
    ('connection addr: ', ('127.0.0.1', 38866))
    Traceback (most recent call last):
      File "netreceive.py", line 15, in <module>
        data = s.recv(BUFFER_SIZE)
    socket.error: [Errno 107] Transport endpoint is not connected

    That's with 'localhost' as the address in Pd and Python. Any ideas what the issue could be?

    What's your Pd patch on Bela?

    I was receiving from Pd on the host computer with something like:
    alt text

    That error is a bit misleading and it happens because the call to send() fails here.

    If you send me your Pd patch I will try to reproduce and get a more meaningful error code.

    alt text

    The patch is essentially the same as the one you had.

    When I start the patch, I get a print in the console of "net: 1", meaning that there is a connection for a second, but then the whole thing stops and I get the errors shown above. Maybe it's an issue with sending to Python...? (though I don't see why that would be any different.)

    Yes that seems something in the python code: also when connecting from non-Bela Pd I get the same outcome:

    ('connection addr: ', ('192.168.7.1', 64514))
    Traceback (most recent call last):
      File "netreceive.py", line 15, in <module>
        data = s.recv(BUFFER_SIZE)
    socket.error: [Errno 107] Transport endpoint is not connected

    In case that helps, here's some debugging info I got from libpd:

    Error during recv(15, 0xb5c7a5a8, 16383, 0): Connection reset by peer (error 104)
    Error during send(15, 0xb5c7a5a8 7, 0) : Broken pipe (error 32)

    Thanks. I'll muddle through and see if I can figure anything out. Will post if I find anything.

    Solved! A UDP connection works.
    alt text

    import socket
    
    UDP_IP = '192.168.1.90'
    UDP_PORT = 3000
    BUFFER_SIZE = 1024
    
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind((UDP_IP, UDP_PORT))
    
    while True:
        data, addr = s.recvfrom(1024)
        print "received: ", data