1
from twisted.internet.protocol import DatagramProtocol
2
from twisted.internet import reactor
3
from twisted.application.internet import MulticastServer
5
class MulticastServerUDP(DatagramProtocol):
6
def startProtocol(self):
7
print 'Started Listening'
8
# Join a specific multicast group, which is the IP we will respond to
9
self.transport.joinGroup('224.0.0.1')
11
def datagramReceived(self, datagram, address):
12
# The uniqueID check is to ensure we only service requests from
14
if datagram == 'UniqueID':
15
print "Server Received:" + repr(datagram)
16
self.transport.write("data", address)
18
# Note that the join function is picky about having a unique object
19
# on which to call join. To avoid using startProtocol, the following is
21
#reactor.listenMulticast(8005, MulticastServerUDP()).join('224.0.0.1')
23
# Listen for multicast on 224.0.0.1:8005
24
reactor.listenMulticast(8005, MulticastServerUDP())