Added valid hostname check and exception handling, also limiting port to 4 digits