def sendData(sock_l, host, port, data):
retry = 0
while retry < 3:
try:
if sock_l[0] == None:
sock_l[0] = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock_l[0].connect((host, port))
dbgPrint("\n-- start connect %s:%d" %(host, port))
d = data
sock_l[0].sendall("%010d%s" %(len(data), data))
count = sock_l[0].recv(10)
if not count:
raise Exception("recv error")
buf = sock_l[0].recv(int(count))
dbgPrint("recv data: %s" % buf)
if buf[:2] == "OK":
retry = 0
break
except:
sock_l[0].close()
sock_l[0] = None
retry += 1
#}}}
# initial status for state machine
#{{{STATE
评论列表
文章目录