For some reason I cannot match select sockets to my dictionary of sockets. The below code creates a dictionary of sockets (which is does) then when someone connects accept (which it doesn’t). It finds ‘s’ in ‘L’, but then cannot socket.error: [Errno 22] Invalid argument
listening = {}
L = []
for link in links:
try:
# listening
listening[link] = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listening[link].bind((host, routers[routername].baseport+links[link].locallink))
listening[link].listen(backlog)
# append routes and listen-list
L.append(listening[link])
except socket.error, (value,message):
print "Could not open socket: " + message
sys.exit(1)
# run loop
input = L
running = 1
while running:
inputready,outputready,exceptready = select.select(input,[],[], 0)
# Sockets loop
for s in inputready:
if s in L:
# handle the server socket
client, address = s.accept()
input.append(client)
Although unsure of all my wrongs in the first attempt, I have since solved my own dilema. @Jeremy was on the right track, but slightly off (probably due to my description). The sockets don’t get referenced outside of
sand therefore do not need to be a dictionary. However, select only takes a list so rather than complicating things with other data types, stick with a list and referencesinstead ofL(sis what you want anyways)