在Linux中,我有一个接口eth5,其IP为10.46.55.106。
我在eth5上看到了多播流:
$ tcpdump -i eth5 host 233.113.216.61 and port 21001
11:18:19.416631 IP 194.0.142.188.48253 > 233.113.216.61.21001: UDP, length 20
11:18:19.450577 IP 194.0.142.188.48253 > 233.113.216.61.21001: UDP, length 20
11:18:19.498923 IP 194.0.142.188.48253 > 233.113.216.61.21001: UDP, length 20
11:18:19.546345 IP 194.0.142.188.48253 > 233.113.216.61.21001: UDP, length 20
但是我在下面的Python代码中看不到多播数据包:
import socket
import struct
import sys
# create a UDP socket
my_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# allow reuse of addresses
my_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
# set multicast interface to local_ip
my_socket.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton('10.46.55.106'))
# Set multicast time-to-live to 2...should keep our multicast packets from escaping the local network
my_socket.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
# Construct a membership request...tells router what multicast group we want to subscribe to
membership_request = socket.inet_aton('233.113.216.51') + socket.inet_aton('10.46.55.106')
# Send add membership request to socket
# See http://www.tldp.org/HOWTO/Multicast-HOWTO-6.html for explanation of sockopts
my_socket.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, membership_request)
my_socket.bind(('0.0.0.0', 21001))
while True:
data, address = my_socket.recvfrom(20)
print "%s says the time is %s" % (address, data)
我想念什么吗?