Moved socket creation to connect to fix timeout error