Using synchronized to prevent race conditions and checking if socket already exists in ip/port before creating one