title: 'socket.error: [Errno 9] Bad file descriptor' as I run my client
body: <p>as I run my client, my server collapse,</p>
  
  <p>it says:</p>
  
  <pre><code>Traceback (most recent call last):
        File "C:/Users/Or/PycharmProjects/2.6/cyber.py", line 17, in &lt;module&gt;
          data = client_socket.recv(1024)
        File "C:\Python27\lib\socket.py", line 174, in _dummy
          raise error(EBADF, 'Bad file descriptor')
      socket.error: [Errno 9] Bad file descriptor
  </code></pre>
  
  <p>server:</p>
  
  <pre><code>import socket
  import random
  import time
  
  server_socket = socket.socket()
  server_socket.bind(('0.0.0.0', 8820))
  server_socket.listen(1)
  
  (client_socket, client_address) = server_socket.accept()
  
  TIME = time.asctime(time.localtime())
  NAME = "Frank"
  RAND = random.randrange(1,10)
  EXIT = client_socket.close()
  options = [TIME, NAME, RAND, EXIT]
  
  data = client_socket.recv(1024)
  if data == str(TIME):
      client_socket.send('Time is: ' + TIME)
  elif data == str(NAME):
      client_socket.send('My name is: ' + NAME)
  elif data == str(RAND):
      client_socket.send(RAND)
  elif data == str(EXIT):
      EXIT
  
  
  
  
  client_socket.close()
  server_socket.close()
  </code></pre>
  
  <p>client:</p>
  
  <pre><code>import socket
  
  my_socket = socket.socket()
  my_socket.connect(('127.0.0.1', 8820))
  
  theData = raw_input("enter command")
  options = ['TIME', 'NAME', 'RAND', 'EXIT']
  for z in options:
      if theData == z:
          my_socket.send(theData)
          data = my_socket.recv(1024)
          print data
      else:
          theData = raw_input("enter a real command")
  </code></pre>
  
  <p>what should I do?</p>