title: Toggle a python boolean from iOS
body: <p>I am following this: <a href="http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server" rel="nofollow">http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server</a> tutorial.</p>
  
  <p>I got this stuff working nice, and being a total noob at this, i can not for the life of me figure out how to add a Python boolean to the 'chatserver.py' document mentioned in the tutorial, pasted below.</p>
  
  <p>Not only do I want to add one, but also to toggle it from the iPhone app with a button, and then request to know it back from the server.</p>
  
  <p>Like, 
   a button to toggle boolean (How to send a toggle message) and how to ask the server what the state of the boolean is</p>
  
  <p>Apologies for this very open question.</p>
  
  <p>Here is the current server: (Uber-complicated, wohoo!) </p>
  
  <pre><code>from twisted.internet.protocol import Protocol, Factory
  from twisted.internet import reactor
  
  
  class IphoneChat(Protocol):
  def connectionMade(self):
      #self.transport.write("""connected""")
      self.factory.clients.append(self)
      print "clients are ", self.factory.clients
  
  def connectionLost(self, reason):
      self.factory.clients.remove(self)
  
  def dataReceived(self, data):
      #print "data is ", data
      a = data.split(':')
      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>