title: Socket recv in Python 3 repeating input over and over
body: <p>I understand that the reason that its sending so much is that I set the recv to 1024 and can change how much is let in by changing that, however I only want just one Hello World sent through. I tried searching the question and nothing really helpful came up. Thanks in advance!!</p>
  
  <p>Server:</p>
  
  <pre><code>#!/usr/bin/python
  import socket
  import sys
  
  
  class Server:
      def __init__(self, sock=None):
          if sock is None:
              self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
              print("socket created")
  
      def bind(self, HOST, PORT):
          try:
              self.sock.bind((HOST, PORT))
          except socket.error as msg:
              print("Bind failed. Error Code : " +
                      str(msg[0]) + "Message " + msg[1])
              sys.exit()
          print("Socket bind complete")
  
      def main_loop(self):
          self.sock.listen(10)
          print("Socket now listening")
          while 1:
              conn, addr = self.sock.accept()
              print("Connected with " + addr[0] + ":" + str(addr[1]))
              data = conn.recv(1024)
              print(data)
          self.sock.close()
  
      def main(self):
          HOST = ''
          PORT = 8888
          self.bind(HOST, PORT)
          self.main_loop()
  
  
  def main():
      server = Server()
      server.main()
  
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>Client</p>
  
  <pre><code>#!/usr/bin/python
  import socket
  import sys
  
  
  class Client:
      def __init__(self, sock=None):
          if sock is None:
              self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
              print("socket created")
  
      def connect(self, HOST, PORT):
          try:
              self.sock.connect((HOST, PORT))
          except socket.error as msg:
              print("Connect failed. Error Code : " +
                      str(msg[0]) + "Message " + msg[1])
              sys.exit()
          print("Socket connect complete")
  
      def main_loop(self):
          while 1:
              self.sock.sendall(b'Hello world')
          self.sock.close()
  
      def main(self):
          HOST = ''
          PORT = 8888
         self.connect(HOST, PORT)
         self.main_loop()
  
  
  def main():
      client = Client()
      client.main()
  
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>Server Output:</p>
  
  <pre><code>socket created
  Socket bind complete
  Socket now listening
  Connected with 127.0.0.1:45676
  b'Hello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello worldHello world'
  </code></pre>
  
  <p>Client Output:</p>
  
  <pre><code>socket created
  Socket connect complete
  </code></pre>