def connect(self):
<EOL>if self.mode and self.mode != '<STR_LIT>':<EOL><INDENT>raise ValueError("<STR_LIT>" %<EOL>self.__class__.__name__)<EOL><DEDENT>self.mode = '<STR_LIT>'<EOL>if self.conn:<EOL><INDENT>return<EOL><DEDENT>fd = socket.create_connection((self.host, self.port))<EOL>self.conn = self.connection_class(fd)<EOL>try:<EOL><INDENT>self.conn.send('<STR_LIT>', self.authkey)<EOL>cmd, payload = self.conn.recv()<EOL>if cmd != '<STR_LIT:OK>':<EOL><INDENT>LOG.error("<STR_LIT>" %<EOL>(self.host, self.port, payload[<NUM_LIT:0>]))<EOL>self.close()<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>exc_type, exc_value, exc_tb = sys.exc_info()<EOL>if exc_type == ValueError:<EOL><INDENT>LOG.error("<STR_LIT>" %<EOL>str(exc_value))<EOL><DEDENT>elif exc_type == ConnectionClosed:<EOL><INDENT>LOG.error("<STR_LIT>" %<EOL>str(exc_value))<EOL><DEDENT>else:<EOL><INDENT>LOG.exception("<STR_LIT>")<EOL><DEDENT>self.close()<EOL>raise exc_type(exc_value).with_traceback(exc_tb)<EOL><DEDENT>
Connect to the server.  This method causes the SimpleRPC
object to switch to client mode.  Note some methods, such as
the ping() method, implicitly call this method.