On 23/01/13 10:28, IOhannes m zmoelnig wrote:
On 2013-01-23 10:22, Lorenzo Sutton wrote:
it seems your example is missing the newline (;\n). iirc I've had
a few pd lockups when sending lots of messages from Processing
without the newline.
Good to know, and easy to add to the script. And of course you
wouldn't really be hard-coding stuff like that. Just for curiosity,
how many is 'lots'?.
Actually... I'm not sure the "\n" is really so relevant for *sending* to
Pd, as if I understand correctly the ";" is...
[netsend] will only emit the message once it receives the terminator.
so it has to buffer all the data, till it encounters the terminator.
and since the term never comes, it will eventually get out of memory.
(and long before that it will start to choke, but *when* is really
depending on your system)
Ok.. but in the example there is no [netsend]... there is [netreceive]
and Python is doing the sending through sockets.
The attached seem to work fine sending the 10000 messages (ready for a
[tabwrite]) down until 0.08s (80 ms) interval, even with dsp turned on.
As soon as the INTERVAL goes below 0.08s (see python script) Pd starts
to choke badly on my system. Again adding an "\n" doesn't seem to be
relevant.
Lorenzo.
#N canvas 639 306 545 359 10;
#X floatatom 386 42 5 0 0 0 - - -;
#X obj 386 62 sel 0;
#X obj 413 86 print CONNECTION(S);
#X msg 386 106 DISCONNECTED;
#X obj 386 125 print --;
#X text 429 41 # of connections;
#X text 44 256 See http://en.wikipedia.org/wiki/FUDI for info about
the message format as well as the [netreceive] help;
#X obj 39 4 netreceive 54321;
#X obj 380 210 table array1 10000;
#X msg 69 152 stop;
#X obj 47 220 dac~;
#X msg 209 195 \; pd dsp \$1;
#X obj 210 160 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
1;
#X obj 47 188 tabplay~ array1;
#X msg 49 129 bang;
#X obj 40 66 print CLIENT;
#X obj 284 99 timer;
#X floatatom 284 130 10 0 0 0 - - -;
#X obj 40 27 route python begin end;
#X obj 169 83 tabwrite array1;
#X msg 284 74 bang;
#X msg 327 74 bang;
#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 7 0 18 0;
#X connect 7 1 0 0;
#X connect 9 0 13 0;
#X connect 12 0 11 0;
#X connect 13 0 10 0;
#X connect 13 0 10 1;
#X connect 13 1 14 0;
#X connect 14 0 13 0;
#X connect 16 0 17 0;
#X connect 18 0 15 0;
#X connect 18 1 20 0;
#X connect 18 2 21 0;
#X connect 18 3 19 0;
#X connect 20 0 16 0;
#X connect 21 0 16 1;
#!/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
import random
# TCP stuff
TCP_IP = '127.0.0.1'
TCP_PORT = 54321
BUFFER_SIZE = 1024
INTERVAL_STEP = 0.001
INTERVAL_MAX = 0.12
INTERVAL_MIN = 0.01
CHOKE_POINT = 0.08
INTERVAL = INTERVAL_MAX # secondsA
# 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."
s.send("python Hello from the python client")
except socket.error as err:
# Exit on error
print "Could not connect. Aborting.\nError: %s" % (err)
sys.exit(1)
while True:
try:
# We send a 'begin' and 'end' which we route in Pd
print "sending..."
s.send("begin;")
for x in range(0,10000):
# Format messages ready for [tabwrite]: [value index(
s.send( ("%f %d;") % (random.random(), x))
time.sleep (INTERVAL)
INTERVAL = INTERVAL - INTERVAL_STEP
print("Interval is now %f" % (INTERVAL))
s.send("end;")
if INTERVAL < CHOKE_POINT:
print('Pd is probably @@@@@ \033[91mCHOKING\033[0m @@@@ now ...')
else:
print('Pd is porbaly ok and !! \033[92mRESPONSIVE\033[0m ! now...')
if (INTERVAL < INTERVAL_MIN) or (INTERVAL >= INTERVAL_MAX):
INTERVAL_STEP = INTERVAL_STEP * -1
print '\033[96m>>>>>>>>>> Inverting interval step... <<<<<\033[0m'
s.send("end;")
except KeyboardInterrupt:
# Press CTRL + C to stop.
s.send("python Bye from python;")
time.sleep(0.2)
print "Closing connection"
s.close()
break
try:
s.close()
except:
pass
_______________________________________________
[email protected] mailing list
UNSUBSCRIBE and account-management ->
http://lists.puredata.info/listinfo/pd-list