[D]于python多线程的问题
# coding:utf-8import threadimport timefrom socket import *import osimport reimport threaddef Socket_Recv_heart(host,port,msg,BF): print 'Begin to connect server and get the DevIpAddress' try: port = int(port) address=(host,port) print address clientSocket=socket(AF_INET,SOCK_STREAM) #创建采用TCP 协议的socket对象 clientSocket.connect(address) #连接指定的服务器端 except: print "Connect failed!" while True: clientSocket.send(msg) msg=clientSocket.recv(BF) if (len(msg) > 0): print msg time.sleep(3)def main(): thread.start_new_thread(Socket_Recv_heart('127.0.0.1',7070,'ccc',1024),()) thread.start_new_thread(Socket_Recv_heart('127.0.0.1',7071,'ccc',1024),())if __name__ == '__main__': main()