how to fill many data strings from socket.recvfrom()

Mark T nospam at nospam.com
Sat Nov 3 20:47:57 EDT 2007


"lgwe" <larsgwest at gmail.com> wrote in message 
news:1194119438.986008.179520 at o80g2000hse.googlegroups.com...
>I want to receive 200 udp datagrams. Each into a new data string.
> But I dont know how to do that, this is wrong:
>
> import socket
> s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
> s.bind(("",port))
> i = 0
> while i<200:
>    data[i],addr = s.recvfrom(1024)
>    i = +1
>
> data[i] is illegal.
>
> Any suggestion welcome!
>

import socket
s=socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind(('',5000))
data=[]
for i in range(200):
    tmp,addr = s.recvfrom(1024)
    data.append(tmp)

-Mark





More information about the Python-list mailing list