fix the bug: socket and packet can be null, and hence cause app dead