moved socket creation to synchronized method

@gsoltis this should fix the race condition that occurred when closing the socket while connecting