error: [errno 9] bad file descriptor
Posted: Tue Mar 25, 2014 9:56 am
Hi,
I have the below code for a socket:
Server side:
Cliente side:
The code go fine, but after sometime I get the error... error: [errno 9] bad file descriptor
I read about this error and I understand that it is because the I am trying connect with the socket but the socket is closed already. But really I don't close the socket, the "s.close()" is out the loop.
Could somebody help me?
Regards
Raul
I have the below code for a socket:
Server side:
Code: Select all
def server():
s = socket.socket()
s.bind(("localhost", 9999))
s.listen(1)
s.setblocking(0)
inputs = [s]
outputs = [ ]
while True:
readable, writable, exceptional=select.select(inputs,outputs,[],0.6)
for sock in readable:
if sock is s:
client,address = sock.accept()
inputs.append(client)
else:
data = sock.recv(1024)
if data=="true":
global MinutoCtr, TCanal1, Canal1
Canal1,TCanal1,Luna,TLuna = readatos()
MinutoCtr = 77
elif data=="status":
outputs.append(client)
else:
sock.close()
if sock in outputs:
outputs.remove(sock)
inputs.remove(sock)
for sock in writable:
sock.send (json.dumps({"IntDia": "%d" % (x),"PWDia":"%d" % (y),"IntNoche": "%d" % (x2)}))
outputs.remove(sock)
s.close()
Code: Select all
s = socket.socket()
try:
s.connect(("localhost", 9999))
s.send("status")
bufsize = 1024
estados=s.recv(bufsize)
print "Content-type:text/html\r\n\r\n"
print estados
except:
print "Content-type:text/html\r\n\r\n"
print (json.dumps({"IntDia": "Sin respuesta"}))
#print
s.close()
I read about this error and I understand that it is because the I am trying connect with the socket but the socket is closed already. But really I don't close the socket, the "s.close()" is out the loop.
Could somebody help me?
Regards
Raul