python 日志收集系统
服务器端:
#!/usr/bin/env python # -*- coding:utf-8 -*- import socket ip_port = ('0.0.0.0',9999) sk = socket.socket() sk.bind(ip_port) sk.listen(5) while True: print 'server waiting...' conn,addr = sk.accept() client_data = conn.recv(1024) print client_data conn.close()
客户端
1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 import socket 4 ip_port = (‘x.x.x.x’,9999) 5 with open('20160617.log','r') as f: 6 for i in f: 7 sk = socket.socket() 8 sk.connect(ip_port) 9 sk.sendall(i) 10 sk.close()