* add door client
[uccvend-vendserver.git] / sql-edition / servers / DoorClient.py
1 #!/usr/bin/python
2
3 from LATClient import LATClient
4 from select import select
5 import sys
6
7 def check_door_service(service, test_string="got wombles?"):
8         latclient = LATClient(service=sys.argv[1])
9         latclient.sock.send(test_string)
10         rfh, wfh = latclient.get_fh()
11         wfh.write(test_string)
12         wfh.flush()
13         rr, wr, er = select([rfh], [], [], 10.0)
14         if rfh not in rr: return "open"
15         recv = rfh.read(len(test_string))
16         if recv <> test_string: return "error"
17         return "closed"
18
19 if __name__ == '__main__':
20         result_codes = { 'open' : 0, 'closed' : 1, 'error' : 2 }
21         result = check_door_service(sys.argv[1])
22         print result
23         sys.exit(result_codes[result])

UCC git Repository :: git.ucc.asn.au