python小程序之并发连接

 1 import threading
 2 import  socket
 3 import time
 4 def conn():
 5     cli = socket.socket()
 6     cli.connect(("58.68.232.139",80))
 7     while True:
 8         data = input(">>>").strip()
 9         if len(data)  == 0:continue
10         cli.send(data.encode())
11         reciv = cli.recv(1024)
12         print(reciv)
13 for i in range(2000):
14     t =threading.Thread(target=conn)
15     t.setDaemon(True)
16     t.start()
17 time.sleep(15)
18 print("--main--")

 

posted @ 2017-01-09 21:40  李瑞鑫  阅读(285)  评论(0编辑  收藏  举报