我知道在端口xxxx上有一个从ip xxx.xxx.xxx.xxx发送的UDP流,我如何在python中接收该数据。
答案 0 :(得分:0)
简单的方法是使用socket
导入套接字
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print "received message:", data