def setEventCast(self, mcast='224.56.56.56', port=45654, bind='0.0.0.0'):
'''
Tie this CobraEventCore to any others which share the same multicast
ip and port. This basically creates a ( udp "unreliable" ) "bus" on
which events are serialized using json.
'''
# Setup a UDP casting socket
self._ce_mcastport = port
self._ce_mcasthost = mcast
self._ce_ecastsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self._ce_ecastsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self._ce_ecastsock.bind((bind,port))
# Join the multicast IP
mreq = struct.pack("4sL", socket.inet_aton(mcast), socket.INADDR_ANY)
self._ce_ecastsock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
thr = threading.Thread(target=self._runSocketListener)
thr.setDaemon(True)
thr.start()
评论列表
文章目录