Fix bad behavor while pinging Clients

fixes #6941
I suggest moving `if (c != null && c.socket != null` before this line, because if `c == null` it will throw here.