Establishes a socket connection