title: exceptions.AttributeError: Python instance has no attribute 'name'
body: <p>I am doing Cesare Rocchi's tutorial "How To Create A Socket Based iPhone App and Server" <a href="http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server#comments" rel="nofollow">http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server#comments</a> </p>
  
  <p>Do I need to define an attribute called 'name' in the "class IphoneChat(Protocol)" or is it inherited from "twisted.internet.protocol?" If it is inherited, how do I access it correctly?</p>
  
  <p>server.py:</p>
  
  <pre><code>from twisted.internet.protocol import Factory, Protocol  
  from twisted.internet import reactor
  class IphoneChat(Protocol):
      def connectionMade(self):
          self.factory.clients.append(self)
          print "clients are", self.factory.clients
  
      def connectionLost(self, reason):
          self.factory.clients.remove(self) 
  
      def dataReceived(self, data):
          a = data.split(':')
          print a 
          if len(a) &gt; 1:
              command = a[0]
              content = a[1]
  
              msg = ""
              if command == "iam":
                  self.name = content
                  msg = self.name + "has joined"
              elif command == "msg":
                  msg = self.name + ": " + content 
                  print msg
  
              for c in self.factory.clients:
                  c.message(msg)
  
      def message(self, message):
          self.transport.write(message + '\n')
  
  factory = Factory()
  factory.protocol = IphoneChat
  factory.clients = []
  reactor.listenTCP(80, factory)
  print "Iphone Chat server started"
  reactor.run()
  </code></pre>
  
  <p>Terminal output:</p>
  
  <pre><code>Iphone Chat server started
  ...
  --- &lt;exception caught here&gt; ---
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/selectreactor.py", line 150, in _doReadOrWrite
      why = getattr(selectable, method)()
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/tcp.py", line 199, in doRead
      rval = self.protocol.dataReceived(data)
    File "server.py", line 30, in dataReceived
      msg = self.name + ": " + content
  exceptions.AttributeError: IphoneChat instance has no attribute 'name'
  </code></pre>
  
  <p>Problem solving steps so far:</p>
  
  <ul>
  <li>I read that "name" is managed server side, in the self.factory.clients list, but then I looked for a class definition of twisted.internet.protocol and found nothing like "name" <a href="http://twistedmatrix.com/documents/11.0.0/api/twisted.internet.protocol.Protocol.html" rel="nofollow">http://twistedmatrix.com/documents/11.0.0/api/twisted.internet.protocol.Protocol.html</a> </li>
  <li>From what I have read elsewhere this could just be an indentation error.</li>
  </ul>