/************************** sender *****************************************/
#!/usr/bin/python
#python v2.7
import socket
HOST='';
PORT=5001
f = open('randomdata','rb')
data = f.read()
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);
s.connect((HOST,PORT));
s.send(data);
s.close()
f.close()
/************************ receiver ****************************/
#!/usr/bin/python
#python v2.7
import socket
HOST = '';
PORT = 5001;
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM);
s.bind((HOST,PORT));
s.listen(1);
conn,addr=s.accept();
print 'connected by ',addr
f = open('rec.data','wb')
while 1:
data = conn.recv(1024);
if not data: break;
f.write(data)
conn.close()
f.close()
阅读(1852) | 评论(0) | 转发(0) |