Twisted Python: multicast server not working as expected
===

I am experimenting with twisted python's multicast protocol. This is a simple example:

I created two servers, listening on 224.0.0.1 and 224.0.0.2 like below:


    from twisted.internet.protocol import DatagramProtocol
    from twisted.internet import reactor
    from twisted.application.internet import MulticastServer
    
    class MulticastServerUDP(DatagramProtocol):
        def __init__ (self, group, name):
            self.group = group
            self.name = name
        def startProtocol(self):
            print '%s Started Listening' % self.group
            # Join a specific multicast group, which is the IP we will respond to
            self.transport.joinGroup(self.group)
    
        def datagramReceived(self, datagram, address):
            print "%s Received:"%self.name + repr(datagram) + repr(address)
    

    reactor.listenMulticast(10222, MulticastServerUDP('224.0.0.1', 'SERVER1'), listenMultiple = True)
    reactor.listenMulticast(10222, MulticastServerUDP('224.0.0.1', 'SERVER2'), listenMultiple = True)
             
    reactor.run()


Then I run this code to send "HELLO":

    import socket
    
    MCAST_GRP = '224.0.0.1'
    MCAST_PORT = 10222
    
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
    sock.sendto("HELLO", (MCAST_GRP, MCAST_PORT))

The results were quite confusing. There are several cases:

-When I set all group IP and MCAST_GRP to 224.0.0.1, both servers received the message (expected) 
-When I set both servers' group IP to 224.0.0.1 and MCAST_GRP in the sending script to 224.0.0.2 (or something different from 224.0.0.1), both servers did not receive the message (expected)

-When I set one server's group IP to 224.0.0.1 and the other 224.0.0.2, strange things happen. When I set MCAST_GRP to 224.0.0.1 or 224.0.0.2, I expected only ONE of the two servers to receive the message. The result was that BOTH servers received the message. I am not sure what is going on. Can someone explain this? 

Note: I am running these on the same machine.


SL