[sc-users] Using natcat for sockets: how make SuperCollider wait for input?

Torsten Anders torsten.anders at plymouth.ac.uk
Fri Sep 7 23:31:48 PDT 2007


Dear all,

this is my next attempt to have sockets in SuperCollider. I meanwhile  
found out about the commandline tool netcat (see http:// 
en.wikipedia.org/wiki/Netcat). The original implementation nc was  
already installed on my Mac ;-)

I can easily call nc from SuperCollider using the Pipe class. For  
example, the following line starts a TCP socket server on the  
localhost and listen (-l) at port (-p) 7777, see "man nc" for details.

   p = Pipe.new("nc -l -p 7777", "r");

I can now send data to my Pipe object, e.g., by entering the  
following at the commandline.

   $ nc localhost 7777
   this is a test

Back in SuperCollider, I receive this string when I evaluate

   p.getLine;

Now, my problem is that I would like SuperCollider to always wait  
until some input arrives at the socket (i.e., the Pipe object) before  
it does something with this input -- and then recursively calls  
p.getLine again. However, if I call p.getLine before the expected  
input was written to the pipe, then it somehow freezes the whole  
SuperCollider application!

I am probably spoiled by using a concurrent logic language (Oz) for  
quite some time. In Oz, I would bind the output of some pipe reading- 
function to a fresh logical variable in a new thread, and then make  
my thread wait until this variable is bound, before I go on with  
processing the output and recursively calling my reading-function again.

How does one approach this issue in SuperCollider? How can I make  
SuperCollider wait until some new input arrives at the pipe before it  
does something with it (and before p.getLine is called again).

Thank you very much indeed!

Best
Torsten

--
Torsten Anders
Interdisciplinary Centre for Computer Music Research
University of Plymouth
http://strasheela.sourceforge.net
http://www.torsten-anders.de




More information about the sc-users mailing list