Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / core / howto / listings / udp / MulticastClient.py
1 from twisted.internet.protocol import DatagramProtocol\r
2 from twisted.internet import reactor\r
3 \r
4 \r
5 class MulticastPingClient(DatagramProtocol):\r
6 \r
7     def startProtocol(self):\r
8         # Join the multicast address, so we can receive replies:\r
9         self.transport.joinGroup("228.0.0.5")\r
10         # Send to 228.0.0.5:8005 - all listeners on the multicast address\r
11         # (including us) will receive this message.\r
12         self.transport.write('Client: Ping', ("228.0.0.5", 8005))\r
13 \r
14     def datagramReceived(self, datagram, address):\r
15         print "Datagram %s received from %s" % (repr(datagram), repr(address))\r
16 \r
17 \r
18 reactor.listenMulticast(8005, MulticastPingClient(), listenMultiple=True)\r
19 reactor.run()\r