Attach server-side WebSocket event handlers before receiving messages