Difference between revisions of "Python: UDP Multicast"
Jump to navigation
Jump to search
Onnowpurbo (talk | contribs) (New page: Transmitter import socket MCAST_GRP = '224.1.1.1' MCAST_PORT = 5007 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) sock.setsockopt(socket.IPPROTO_IP,...) |
Onnowpurbo (talk | contribs) |
||
Line 1: | Line 1: | ||
− | Transmitter | + | Tambahkan routing |
+ | |||
+ | sudo su | ||
+ | route add -net 224.0.0.0 netmask 255.0.0.0 eth0 | ||
+ | ifconfig eth0 allmulti | ||
+ | |||
+ | |||
+ | Script Transmitter | ||
import socket | import socket | ||
Line 11: | Line 18: | ||
− | Receiver | + | Script Receiver |
import socket | import socket |
Revision as of 05:34, 7 May 2014
Tambahkan routing
sudo su route add -net 224.0.0.0 netmask 255.0.0.0 eth0 ifconfig eth0 allmulti
Script Transmitter
import socket MCAST_GRP = '224.1.1.1' MCAST_PORT = 5007 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) sock.sendto("robot", (MCAST_GRP, MCAST_PORT))
Script Receiver
import socket import struct MCAST_GRP = '224.1.1.1' MCAST_PORT = 5007 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind((, MCAST_PORT)) mreq = struct.pack("4sl", socket.inet_aton(MCAST_GRP), socket.INADDR_ANY) sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) while True: print sock.recv(10240)