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

L

lgwe

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,addr = s.recvfrom(1024)
i = +1

data is illegal.

Any suggestion welcome!
 
G

GuillaumeC

data 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)
 
M

Mark T

lgwe said:
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,addr = s.recvfrom(1024)
i = +1

data 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top