Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / pair / examples / pairudp.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 from twisted.internet import reactor, protocol
5 from twisted.pair import ethernet, rawudp, ip
6 from twisted.pair import tuntap
7
8 class MyProto(protocol.DatagramProtocol):
9     def datagramReceived(self, *a, **kw):
10         print a, kw
11
12 p_udp = rawudp.RawUDPProtocol()
13 p_udp.addProto(42, MyProto())
14 p_ip = ip.IPProtocol()
15 p_ip.addProto(17, p_udp)
16 p_eth = ethernet.EthernetProtocol()
17 p_eth.addProto(0x800, p_ip)
18
19 reactor.listenWith(tuntap.TuntapPort,
20                    interface='tap0', proto=p_eth, reactor=reactor)
21 reactor.run()