blob: 69be26064f079c970ca2bd84a8773be90ea23adf [file] [log] [blame]
Mark Sleec9676562006-09-05 17:34:52 +00001from thrift.Thrift import TProcessor
2from thrift.transport import TTransport
3
4class TServer:
5
6 """Base interface for a server, which must have a run method."""
7
8 def __init__(self, proc):
9 self.processor = proc
10
11 def run(self):
12 pass
13
14class TSimpleServer(TServer):
15
16 """Simple single-threaded server that just pumps around one transport."""
17
18 def __init__(self, proc, trans):
19 TServer.__init__(self, proc)
20 self.transport = trans
21
22 def run(self):
23 self.transport.listen()
24 while True:
25 client = TTransport.TBufferedTransport(self.transport.accept())
26 try:
27 while True:
28 self.processor.process(client, client)
29 except Exception, x:
30 print x
31 print 'Client died.'
32 client.close()