I've been testing Caddy Server and Web Socket Daemon to see how easy it is to support WebSockets from a server environment. Both of these solutions are abstractions that use standard input/output from a command line program of your choosing (written in any language of your choosing).
However, both programs are line-based. That is, if your command line program writes a single "message" to standard output that contains a newline character, your JavaScript websocket code will see two distinct messages.
Is there any way to avoid this problem?
EDIT: As an unofficial answer, you can perform multiple encodings to avoid the newline issue. For example, if your command line program is responding with JSON-encoded data, you can simply base64 encode the data before writing it to standard output. The JavaScript would then call atob()
on this data before JSON-decoding it. Using multiple encodings adds a slight size overhead but it does avoid issues with the newline character (and potentially any other issues with other non-printing and control characters).