def serve(self, conn, addr, auth=False):
try:<EOL><INDENT>while True:<EOL><INDENT>try:<EOL><INDENT>cmd, payload = conn.recv()<EOL><DEDENT>except ValueError as exc:<EOL><INDENT>conn.send('<STR_LIT>', "<STR_LIT>" % str(exc))<EOL>if not auth:<EOL><INDENT>return<EOL><DEDENT>continue  <EOL><DEDENT>LOG.debug("<STR_LIT>" %<EOL>(cmd, addr[<NUM_LIT:0>], addr[<NUM_LIT:1>], payload))<EOL>if cmd == '<STR_LIT>':<EOL><INDENT>if auth:<EOL><INDENT>conn.send('<STR_LIT>', "<STR_LIT>")<EOL><DEDENT>elif payload[<NUM_LIT:0>] != self.authkey:<EOL><INDENT>conn.send('<STR_LIT>', "<STR_LIT>")<EOL>return<EOL><DEDENT>else:<EOL><INDENT>conn.send('<STR_LIT:OK>')<EOL>auth = True<EOL><DEDENT><DEDENT>elif not auth:<EOL><INDENT>conn.send('<STR_LIT>', "<STR_LIT>")<EOL>return<EOL><DEDENT>elif cmd == '<STR_LIT>':<EOL><INDENT>conn.send('<STR_LIT>', *payload)<EOL><DEDENT>elif cmd == '<STR_LIT>':<EOL><INDENT>try:<EOL><INDENT>try:<EOL><INDENT>funcname, args, kwargs = payload<EOL><DEDENT>except ValueError as exc:<EOL><INDENT>conn.send('<STR_LIT>', "<STR_LIT>"<EOL>"<STR_LIT>" % str(exc))<EOL>continue<EOL><DEDENT>func = self._get_remote_method(funcname)<EOL>result = func(*args, **kwargs)<EOL><DEDENT>except Exception as exc:<EOL><INDENT>exc_name = '<STR_LIT>' % (exc.__class__.__module__,<EOL>exc.__class__.__name__)<EOL>conn.send('<STR_LIT>', exc_name, str(exc))<EOL><DEDENT>else:<EOL><INDENT>conn.send('<STR_LIT>', result)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>conn.send('<STR_LIT>', "<STR_LIT>" % cmd)<EOL><DEDENT><DEDENT><DEDENT>except ConnectionClosed:<EOL><INDENT>pass<EOL><DEDENT>except Exception as exc:<EOL><INDENT>LOG.exception("<STR_LIT>" %<EOL>(addr[<NUM_LIT:0>], addr[<NUM_LIT:1>], str(exc)))<EOL><DEDENT>finally:<EOL><INDENT>LOG.info("<STR_LIT>" %<EOL>(addr[<NUM_LIT:0>], addr[<NUM_LIT:1>]))<EOL>conn.close()<EOL><DEDENT>
Handle a single client.

:param conn: The Connection instance.
:param addr: The address of the client, for logging purposes.
:param auth: A boolean specifying whether the connection
             should be considered authenticated or not.
             Provided for debugging.