connectAndGetSocket method added.