Fixed an issue with the PingThread.

The checking of the connection state wasn't implemented in a good way,
only sometimes did the PingThread actually manage to start detecting
changes. Most times however the state was percieved as disconnected or
connecting, and because of this it wasn't sending ping requests.