The way socket servers and client programs work, this is mainly determined by the server side program. If the server side socket is allowed to response to a reuqest to run the foo() function, then it can execute the function. The client side program does not have much control on it. Client side can only initiate a request, say with an ID number 3021. Server side program checks the id number from the request and if the client is authenticated and the id number is associated with the function then the server program starts the function.
More details would be helpful to see if it can be done what you are really trying to do. If you are writing the program in any version of C or VC++, you can post a new thread in C forum. There are some netwroking experts talk in there.
_________________
Dust fills my eyes / Clouds roll by / and I roll with them / Centuries cry / Orders fly / and I fall again
Afford best design, implement best solution. Outsource your web design.