Reputation: 508
I've got a simple pub/sub system that works on linux using UDP sockets, but doesn't work on Mac OS X (specifically 10.10.3). Is there something I can change to allow it to work on my mac?
pub.py:
import sys
import socket
sender = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sender.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
while True:
line = sys.stdin.readline()
if not line: break
sender.sendto(line,("127.255.255.255",4321))
sub.py:
import sys
import socket
receiver = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
receiver.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR, 1)
receiver.bind(('',4321))
while True:
data,addr = receiver.recvfrom(1500)
sys.stdout.write(data)
To run it I start multiple instances of sub.py in separate windows. In one window I start pub.py and type stuff into stdin (pressing return), and it shows up on both recipients. It works on a recent versions of Linux Mint and Centos.
Upvotes: 0
Views: 1599
Reputation:
It's the 127.255.255.255
. 127.0.0.1
works fine.
Mac OS X's loopback interface doesn't support broadcasts.
Upvotes: 2