process individual commands

So I am not sure if this is possible or if there is a better way to perform this task, but I am attempting to create a single ajax connection to a server-side script that basically relays function calls to the page by constantly listening to a named pipe. So, for example, I could do something like:

# echo "foo(param1,param2)" > /path/to/pipe/gui

which would pass the 'foo' function to the page to be executed. The ajax connection needs to be permanent basically (controlled via timeout?) or by using an occasional 'ping' to keep it open.

Currently I have a basic test, but I am not sure how to process each received call in ajax. I am using the readyState==3 to simple call an alert() with each passed string from the named pipe, but it seems to always return everything submitted. So if I have done:

# echo 'hello' > /path/to/pipe/gui

It will show an alert popup with 'hello' in it. If I then do:

# echo 'world' > /path/to/pipe/gui

It will then show an alert popup with:


Again, I am not sure if there is a better way to approach this or even if there is some library already built to handle something like this. Any help would be appreciated!

UPDATE: The comments say to use websockets and (which I think uses websockets), but I don't want to add a bunch of servers. Any solutions need to keep standard webbrowsers and web servers.