On 21/01/13 18:52, Pierre Massat wrote:
Assuming that i can find a description of this protocol, how would I use it to communicate between Pd and Python ? I guess this more a question to ask in a Python forum, but still, i'd love to have at least some hints...
In python use sockets... in Pd use [netreceive] - I'm sure there's loads of good examples out there and I'm working on some pygtk for a project (but it's still very very early). Menwhile this is a very minimal python -> Pd example
Lorenzo.
Cheers, Pierre. 2013/1/21 Jonathan Wilkes <jancs...@yahoo.com <mailto:jancs...@yahoo.com>> ----- Original Message ----- > From: Hans-Christoph Steiner <h...@at.or.at <mailto:h...@at.or.at>> > To: pd-list@iem.at <mailto:pd-list@iem.at> > Cc: > Sent: Monday, January 21, 2013 11:17 AM > Subject: Re: [PD] Pd --> Python, IPC, FUDI, pdreceive, et cetera ! > > > FUDI is not just netsend/netreceive, its all Pd messages, including what > pd-gui sends to pd. Its basically space-separated data terminated with a > semi-colon and a newline i.e. ;\n Someone should add the description of the FUDI protocol to the man pages for pdsend/pdreceive, since its not a standard protocol and is slightly different from the messages people are used to sending from within the gui (i.e., without a terminating semicolon). -Jonathan > > .hc > > On 01/21/2013 09:42 AM, Pierre Massat wrote: >> Dear List, >> >> I've been working a lot with Python and Pd lately, and i would like to > have >> better means of communication between the two. >> I know next to nothing about inter-process communication, I know nothing >> about FUDI (except that it's the protocol used by pdsend and > pdreceive), >> and I have no idea what pdreceive was originally designed for. I've > only >> used the subprocess (formerly popen) module in python, but i don't know > how >> to use it with streams of messages coming from the standard output of a >> running process. >> I don't want to use libpd for now because i only need to send and > receive >> simple messages between Python and Pd. >> >> Can someone please provide a few hints ? >> >> Cheers! >> >> Pierre. >> >> >> >> _______________________________________________ >> Pd-list@iem.at <mailto:Pd-list@iem.at> mailing list >> UNSUBSCRIBE and account-management -> > http://lists.puredata.info/listinfo/pd-list >> > > _______________________________________________ > Pd-list@iem.at <mailto:Pd-list@iem.at> mailing list > UNSUBSCRIBE and account-management -> > http://lists.puredata.info/listinfo/pd-list > _______________________________________________ Pd-list@iem.at <mailto:Pd-list@iem.at> mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list _______________________________________________ Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
#N canvas 635 330 439 281 10; #X floatatom 215 70 5 0 0 0 - - -; #X obj 215 90 sel 0; #X obj 242 114 print CONNECTION(S); #X msg 215 134 DISCONNECTED; #X obj 215 153 print --; #X floatatom 54 94 5 0 0 0 - - -; #X obj 40 147 print raw_tcp; #X text 258 69 # of connections; #X obj 54 70 route count foo; #X floatatom 97 94 5 0 0 0 - - -; #X text 38 183 Print the incoming tcp in the message window; #X text 40 201 See http://en.wikipedia.org/wiki/FUDI for info about the message format as well as the [netreceive] help; #X obj 40 40 netreceive 54321; #X connect 0 0 1 0; #X connect 1 0 3 0; #X connect 1 1 2 0; #X connect 3 0 4 0; #X connect 8 0 5 0; #X connect 8 1 9 0; #X connect 12 0 6 0; #X connect 12 0 8 0; #X connect 12 1 0 0;
#!/usr/bin/env python """ Simple example of sending a counter via TCP to Pure Data on localhost. In PD the [netreceive] object must use the same port specified by TCP_PORT. Python sockets part based on Python tcp documentation. """ import socket import time import sys # TCP stuff TCP_IP = '127.0.0.1' TCP_PORT = 54321 BUFFER_SIZE = 1024 # A counter counter = 0 # Try to open the connection to PD print ("Opening connection on port %d") % (TCP_PORT) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print ("Connencting...") try: s.connect((TCP_IP, TCP_PORT)) print "Connected. Press CTRL + C to exit." except socket.error as err: # Exit on error print "Could not connect. Aborting.\nError: %s" % (err) sys.exit(1) # A dictionary for possibly multiple messages messages = {} s.send ("Hello from Python!;") while True: try: messages['count'] = counter messages['foo'] = counter * 2 for k in messages.keys(): # Here the semicolon (";") is important!! See http://en.wikipedia.org/wiki/FUDI message_string = ("%s %d;") % (k, messages[k]) print "Sending %s" % (message_string) s.send(message_string) counter += 1 time.sleep (1) except KeyboardInterrupt: # Press CTRL + C to stop. s.send("Bye from python;") time.sleep(0.2) print "Closing connection" s.close() break try: s.close() except: pass
_______________________________________________ Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list