471,325 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

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

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!

Nov 3 '07 #1
2 3035
data[i] is illegal.
Any suggestion welcome!
Either initialize data before: data=[0]*200 before "while" or
(better):
....
i=0
data=[]
for i in range(200):
d,addr= s.recvfrom(1024)
data.append(d)
Nov 3 '07 #2

"lgwe" <la*******@gmail.comwrote in message
news:11**********************@o80g2000hse.googlegr oups.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
Nov 4 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Gordon Wetzstein | last post: by
8 posts views Thread by simon place | last post: by
5 posts views Thread by Terry | last post: by
2 posts views Thread by Vitali Gontsharuk | last post: by
1 post views Thread by Jack | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.