Script-Fu Server is an extension to GIMP which lets you send arbitrary Scheme code over a socket for a running GIMP process to execute.
Each message sent should comprise a single Scheme expression -- but you can wrap multiple expressions within a 'begin' block if necessary, so this is not a problem.
This article provides a good overview of Script-fu Server, though the Perl stuff is not necessarily up-to-date.