I have to write a program that serves multiple clients that access multiple resources (webcams) at the same time.
Example: clients A and B both asks for the current position of two pan-tilt cameras A and B. I have to avoid that the clients speak directly to that cameras (as there can be many clients) So my idea was to have a process for each client (who connects through a socket) and a process for each cam.
If a client requests the position for cam A the program forks new process for that cam, and that process polls the cam position repeatedly for 10 seconds and then exits. Within that 10 second period each position request from any client should be served by this cam-A process.
The problem is: How can the cam processes communicate with the client processes? My naive approach is the use of global variables (camA-posX, camA-posY, camB-posX, camB-posY,...) that the cam processes write to and the client processes read from. I even don't know if globals between forked processes are possible at all.
My second approach is to use pipes like in perlipc/Safe Pipe Opens but this only covers parent-child communication.
Another problem: There must be someone (the parent process?) who has to decide if I have to fork a new cam process or if it is still running.
Maybe it's even better to write two programs (using the second approach), one for the clients and one for the cameras, that communicates through a single socket with each other.
If the number of cams and clients raise there even might be a need of scaling the whole thing to distribute the load.