title: Asynchronous Socket
body: <p>How do I connect with multiple clients? Once connected with multiple clients how do I receive individual data from each? From what I know I need to use something called "Asyncore". How do I implement this?</p>
  
  <p>Client Class</p>
  
  <pre><code>import socket
  class Client():
      def __init__(self):
          self.host = 'localhost'
          self.port = 5000
  
          self.s = socket.socket()
          self.s.connect((self.host, self.port))
          self.s.send(str.encode(input("What is your name ")))
  
  x = Client()
  </code></pre>
  
  <p>Host Class</p>
  
  <pre><code>import socket
  class Host():
      def __init__(self):
          self.host = 'localhost'
          self.port = 5000
  
          self.s = socket.socket()
          self.s.bind((self.host, self.port))
          self.s.listen(5)
          self.c, self.addr = self.s.accept()
          print("User from " + str(self.addr) + " has connected")
          while True:
              data = self.c.recv(1024)
              if not data:
                  break
  
              print(str(self.addr) +" name is " + data.decode("utf-8"))
              #c.send(str.encode(whatever))
          self.c.close()
  
  x = Host()
  </code></pre>