We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everyone, just like the title says, I want to share a quick and easy way of communicating 2 running sketches by means of a named pipe (also known as a FIFO), first you simply create the pipe, then make one sketch write to it and the other read from it and thats it, this should work pretty much the same in OSX and linux, heres a video I took showcasing it:
and here's an updated version of those sketches only this time they do the reading and writing with a thread so they do not halt when one isn't reading or writing:
sketch that reads the pipe:
PVector p = new PVector();
void setup() {
size(displayWidth/3, displayHeight/3);
fill(255);
}
void draw() {
background(0);
ellipse(p.x, p.y, 30, 30);
thread("readPipe");
}
void readPipe() {
String[] s = loadStrings("../myfifo");
p.set(float(s[0]), float(s[1]));
}
sketch that writes to the pipe:
PVector mouse = new PVector();
void setup() {
size(displayWidth/3, displayHeight/3);
fill(0);
}
void draw() {
background(255);
mouse.set(mouseX, mouseY);
ellipse(mouse.x, mouse.y, 30, 30);
thread("writeToPipe");
}
void writeToPipe() {
saveStrings("../myfifo", str(mouse.array()));
}
Saludos everyone! JLafarga
Comments
So this is faster than using the Serial port library?
The serial port library cannot be used to make two sketches to communicate when they are on the same computer. Which seems to be the choice here.
Oh, you're right. I mean the "net" library. I remember the SharedCanvasClient/Server example to be slow.
I haven't tried, but this can be slower than by using the Net library... Disk I/O isn't particularly fast.