Updated server code with small optimization for WebSocket messages.