Updated socket code to continuously attempt to establish a connection until it succeeds.