~cbehrens/nova/lp844160-build-works-with-zones

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/core/examples/echoclient_udp.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
 
4
# See LICENSE for details.
 
5
 
 
6
 
 
7
from twisted.internet.protocol import DatagramProtocol
 
8
from twisted.internet import reactor
 
9
 
 
10
class EchoClientDatagramProtocol(DatagramProtocol):
 
11
    strings = [
 
12
        "Hello, world!",
 
13
        "What a fine day it is.",
 
14
        "Bye-bye!"
 
15
    ]
 
16
    
 
17
    def startProtocol(self):
 
18
        self.transport.connect('127.0.0.1', 8000)
 
19
        self.sendDatagram()
 
20
    
 
21
    def sendDatagram(self):
 
22
        if len(self.strings):
 
23
            datagram = self.strings.pop(0)
 
24
            self.transport.write(datagram)
 
25
        else:
 
26
            reactor.stop()
 
27
 
 
28
    def datagramReceived(self, datagram, host):
 
29
        print 'Datagram received: ', repr(datagram)
 
30
        self.sendDatagram()
 
31
 
 
32
def main():
 
33
    protocol = EchoClientDatagramProtocol()
 
34
    t = reactor.listenUDP(0, protocol)
 
35
    reactor.run()
 
36
 
 
37
if __name__ == '__main__':
 
38
    main()