Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 746 | olof | 1 | from TCPClient import TCPClient |
| 2 | import time |
||
| 3 | import signal |
||
| 4 | import sys |
||
| 5 | |||
| 6 | HOST = 'sra.eta.chalmers.se' |
||
| 7 | PORT = 8002 |
||
| 8 | |||
| 9 | client = None |
||
| 10 | serverPort = None |
||
| 11 | terminated = False |
||
| 12 | |||
| 13 | def sigIntHandler(signum, frame): |
||
| 14 | print 'Interrupted, exiting' |
||
| 15 | client.disconnect() |
||
| 16 | sys.exit(0) |
||
| 17 | |||
| 18 | def Main(): |
||
| 19 | |||
| 20 | signal.signal(signal.SIGINT, sigIntHandler) |
||
| 21 | client = TCPClient(HOST, PORT) |
||
| 22 | |||
| 23 | print 'Connecting to ' + HOST + ':' + str(PORT) + ' ..' |
||
| 24 | if not client.connect(10): |
||
| 25 | print 'Connection to host failed' |
||
| 26 | sys.exit(-1) |
||
| 27 | |||
| 28 | runTime = 0 |
||
| 29 | while not terminated: |
||
| 30 | data = client.read() |
||
| 31 | if data is not None: |
||
| 32 | print data |
||
| 33 | time.sleep(0.1) |
||
| 34 | runTime += 0.1 |
||
| 35 | if runTime > 10: |
||
| 36 | print 'Terminating' |
||
| 37 | break |
||
| 38 | |||
| 39 | Main() |