0

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().

Shane O
  • 85
  • 2
  • 10

1 Answers1

0

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.

retracile
  • 12,167
  • 4
  • 35
  • 42
  • If you iterate over a list, deleting elements from that *same* list, you may not get everything you expect. Try a couple simple experiments. – retracile Nov 03 '11 at 01:17
  • ok, i will. appreciate the enumerate idea. I'll definitely will be using this now. – Shane O Nov 03 '11 at 01:33