socket.error: (9, 'Bad file descriptor')

Pedro Rodriguez pedro_rodriguez at club-internet.fr
Mon Dec 30 06:10:59 EST 2002


On Sun, 29 Dec 2002 15:03:42 +0000, Fabian Lienert wrote:

> --
> import socket
> 
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.bind(('localhost', 99999))
> s.listen(1)
> conn, addr = s.accept()
> print 'Connected by', addr
> while 1:
>      data = conn.recv(1024)
>      if not data: break
>      elif data == 'cpuload\n' or data == 'cpuload' :
>          conn.send("Hier die CPU Aktivitaet:\n")
> #    conn.send(data + "\n")
>      conn.close()
       ^^^^^^^^^^^^

You are closing the socket too soon !!!
This line should be 'dedented' and be put at the same level
than the 'while'.

BTW, I don't think using a port above 65535 is recommended.
Have a look at 'netstat -a', and you'll noticed that your
port number as been 'reduced' to 16 bits.

Pedro



More information about the Python-list mailing list