Fixed a delete-while-iterate bug in event and timer that can cause a timer function to be called even after it is deleted. Added tcp client connect logic including timeouts and remote disconnects.