#!/usr/bin/env python
# -*- coding: utf-8 -*-
from socket import *
import os
import yaml
def client(filename):
HOST='localhost'
PORT=8081
ADDR = (HOST,PORT)
BUFSIZE = 1024
FILEINFO_SIZE=os.path.getsize(filename)
print FILEINFO_SIZE,filename
fhead='%d \n %s'% (FILEINFO_SIZE,filename)
sendSock = socket(AF_INET,SOCK_STREAM)
sendSock.connect(ADDR)
sendSock.send(fhead)
fp = open(filename,'rb')
while 1:
filedata = fp.read(BUFSIZE)
if not filedata: break
sendSock.send(filedata)
print "文件传送完毕,正在断开连接..."
fp.close()
sendSock.close()
print "连接已关闭..."
client('server.py')