title: Python sockets. OSError: [Errno 9] Bad file descriptor
body: <p>It's my client:</p>
  
  <pre><code>#CLIENT
  import socket
  conne = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  conne.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
  i=0
  while True:
      conne.connect ( ('127.0.0.1', 3001) )
      if i==0:
          conne.send(b"test")
          i+=1
      data = conne.recv(1024)
      #print(data)
      if data.decode("utf-8")=="0":
          name = input("Write your name:\n")
          conne.send(bytes(name, "utf-8"))
      else:
          text = input("Write text:\n")
          conne.send(bytes(text, "utf-8"))
      conne.close()
  </code></pre>
  
  <p>It's my server:</p>
  
  <pre><code>#SERVER
  
  import socket
  
  counter=0
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  sock.bind(('', 3001))
  sock.listen(10)
  
  while True:
      conn, addr = sock.accept()
      data = conn.recv(1024)
      if len(data.decode("utf-8"))&gt;0:
          if counter==0:
              conn.send(b"0")
              counter+=1
          else:
              conn.send(b"1")
              counter+=1
      else:
          break
          print("Zero")
          conn.send("Slava")
      conn.close()
  ))
  </code></pre>
  
  <p>After starting Client.py i get this error:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):   File "client.py", line 10, in
    
        conne.connect ( ('127.0.0.1', 3001) ) OSError: [Errno 9] Bad file descriptor</p>
  </blockquote>
  
  <p>Problem will be created just after first input.
  This program - chat. Server is waiting for messages. Client is sending.</p>