You can find a socket sample in the fftab plugin. Here is an untested approximative sample :
function write(txt) {
var sock=FARR.newTCPSocket("localhost",4242);
sock.write(txt);
sock.close();
}
function read(txt) {
var sock=FARR.newTCPSocket("localhost",4242);
do {
var fragment=sock.read();
content+=fragment;
} while(!content.match(/END_OF_TRANSMISSION$/))
sock.close();
}
You have to test for something while reading to detect when stopping to read since a read of 0 length can be caused by latency. Note that the loop will use maximum cpu. It would probably better to read asynchronously in a timer.