Use json scanner to parse requests over websockets. Don't send newlines from js; send json {"raw":"cmd"} instead of just cmd.