title: Python socket loop does not break
body: <p>I created socket for two PC, one is Raspberry Pi and the other one is my laptop. I just connected two then I send string to test the connection. If I send a character "q" from the RPi, my PC should break out of the loop and close the connection but it does not. The part <code>print("Listening")</code> is still running. Why? See code below.</p>
  
  <pre><code>import socket
  import time
  
  # IP address of this PC.
  TCP_IP = '192.168.137.1'
  
  # Port.
  TCP_PORT = 5005
  
  # Size of buffer.
  BUFFER_SIZE = 1024
  
  # Create a socket, connect and listen to it.
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.bind((TCP_IP, TCP_PORT))
  s.listen(1)
  
  conn, addr = s.accept()
  print('Connection address:', addr)
  
  while 1:
      print("Listening")
      data = conn.recv(BUFFER_SIZE)
      data = data.decode()
  
      if data=='q':
          break
  
      if  data: 
          print ("Received data:", data)
          # Echo back. 
          conn.send(data.encode())
  
      time.sleep(1)
  
  print("It breaks.") 
  conn.close()
  s.close()
  </code></pre>