Search code examples
pythonsocketsudpblendersocketserver

checking for disconnected clients in a list? in python


Okay so this is what I'm trying to do in my python socket server.
I'm trying to have a way for my server to send data. But if it finds a disconnected client in the list of address's that is be used. To remove it from the list. Also, I'm using UDP for sending data. As this is for a gaming server. Something sorta like:

for item in AddressList:
   if item != errno[10054]:  
      sendto("data here", item)   
   else:   
      del(AddressList["spot where error occurred"])  

hope this will help give an idea of what i'm trying to do. before you say "why don't you just use socket.select?" Well, from what i tried, i couldn't get UDP to work in socket.select. And doing TCP the way i'm doing in my game engine, (which i'm using blender) freezes when i do recv().


Solution

  • You can use enumerate to give you the index along with the item. But remember that lists are mutable; you need to be careful modifying the list you are iterating over.