test_socket.py
| 1 |
import socket |
|---|---|
| 2 |
import time |
| 3 |
import traceback |
| 4 |
|
| 5 |
host = '10.0.0.9'
|
| 6 |
port = 9761
|
| 7 |
|
| 8 |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 9 |
s.connect((host, port)) |
| 10 |
|
| 11 |
while True: |
| 12 |
time.sleep(5)
|
| 13 |
data = ''
|
| 14 |
|
| 15 |
try:
|
| 16 |
data = s.recv(1, socket.MSG_DONTWAIT)
|
| 17 |
except socket.error, ex:
|
| 18 |
print "Exception:", type(ex) |
| 19 |
print traceback.format_exc()
|
| 20 |
except Exception, ex: |
| 21 |
print "Exception:", type(ex) |
| 22 |
print traceback.format_exc()
|
| 23 |
|
| 24 |
print data
|
| 25 |
|
| 26 |
|
| 27 |
|