Updated write method for TCP sock; added timeouts; and added necessary functions