Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import sys |
| 4 | sys.path.append('../../../target/gen-py') |
| 5 | |
| 6 | from packetstreamer import PacketStreamer |
| 7 | from packetstreamer.ttypes import * |
| 8 | |
| 9 | from thrift import Thrift |
| 10 | from thrift.transport import TSocket |
| 11 | from thrift.transport import TTransport |
| 12 | from thrift.protocol import TBinaryProtocol |
| 13 | |
| 14 | try: |
| 15 | |
| 16 | # Make socket |
| 17 | transport = TSocket.TSocket('localhost', 9090) |
| 18 | |
| 19 | # Buffering is critical. Raw sockets are very slow |
| 20 | transport = TTransport.TFramedTransport(transport) |
| 21 | |
| 22 | # Wrap in a protocol |
| 23 | protocol = TBinaryProtocol.TBinaryProtocol(transport) |
| 24 | |
| 25 | # Create a client to use the protocol encoder |
| 26 | client = PacketStreamer.Client(protocol) |
| 27 | |
| 28 | # Connect! |
| 29 | transport.open() |
| 30 | |
| 31 | while 1: |
| 32 | packets = client.getPackets("session1") |
| 33 | print 'session1 packets num: %d' % (len(packets)) |
| 34 | count = 1 |
| 35 | for packet in packets: |
| 36 | print "Packet %d: %s"% (count, packet) |
| 37 | if "FilterTimeout" in packet: |
| 38 | sys.exit() |
| 39 | count += 1 |
| 40 | |
| 41 | # Close! |
| 42 | transport.close() |
| 43 | |
| 44 | except Thrift.TException, tx: |
| 45 | print '%s' % (tx.message) |
| 46 | |
| 47 | except KeyboardInterrupt, e: |
| 48 | print 'Bye-bye' |