NetUtils.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:MyPythonLib 作者: BillWang139967 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号