Fixes NPE when writing to disconnected client, Issue #2577
Merge pull request #2578 from kfeuz/Issue2577

Fixes NPE when writing to disconnected client, Issue #2577