blob: 5c9890e80a988df4dd6b62702d00674db61c3541 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001#!/usr/bin/env python
2
3import sys
4sys.path.append('../../../target/gen-py')
5
6from packetstreamer import PacketStreamer
7from packetstreamer.ttypes import *
8
9from thrift import Thrift
10from thrift.transport import TSocket
11from thrift.transport import TTransport
12from thrift.protocol import TBinaryProtocol
13
14try:
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
44except Thrift.TException, tx:
45 print '%s' % (tx.message)
46
47except KeyboardInterrupt, e:
48 print 'Bye-bye'