ifstream in(filename);
if (!in)
{
printf("cannot open file or file not exist.\n"); //文件是否正确打开,打开错误则退出
send(my.skt,"q",1,0); //向客户发送退出信息
closesocket(my.skt); //解除客户连接;
return 0;
}
char ch;
int len=0;
while(in.get(ch))
{
len++; //get file lenght
}
in.close();
str2[0]='O';
str2[1]='K';
str2[2]=len/1000;
str2[3]=(len%1000)/100;
str2[4]=(len%100)/10;
str2[5]=len%10;
printf("%s",str2);
send(my.skt,str2,6,0); //发OK+文件长度
in.open(filename);
if (!in)
{
printf("cannot open file or file not exist.\n"); //文件是否正确打开,打开错误则退出
send(my.skt,"q",1,0); //向客户发送退出信息
closesocket(my.skt); //解除客户连接;
return 0;
}