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