客户端 #!/usr/bin/env python # -*- coding:utf-8 -*- import socket from time import sleep ip_port = ('127.0.0.1',9999) b=0 while True: with open('1.txt','r') as f: for c,i in enumerate(f,1): if c > b: b = c print b,i sk = socket.socket() sk.connect(ip_port) sk.sendall(i) sleep(1) sk.close()
服务器端 #!/usr/bin/env python # -*- coding:utf-8 -*- import socket ip_port = ('127.0.0.1',9999) sk = socket.socket() sk.bind(ip_port) sk.listen(5) while True: conn,addr = sk.accept() client_data = conn.recv(1024) print client_data conn.close()