Fixed a on_connected() bug

Socket's on_connected() would not always be called when it should. Bug
was fixed and an unit test added