?? filet.cpp
字號(hào):
/*this file include fileT function this function used to transfer a file include reciver or send
it's only send file named tmpsendfile.dat and reciver file is saved as tmpgetfile.dat
double parament first told the model and second send the ip address
*/
#include"fileT.h"
//文件的打開(kāi)寫(xiě)入 傳送……
int fileT(int tmp,char *netaddr)
{
char buff[BUFFMAXSIZE];
int len,sock,ret,i=1,errtime=0;
//int tmp;
BIO *f_in;
BIO *f_out;
BIO *n_in;
BIO *n_out;
char fsn[255],frn[255];
//printf("select: 1 sender or 2 receiver ");
//scanf("%d",&tmp);
if(tmp==0)
{
//sender
//printf("\ninput file name:");
//scanf("%s",fsn);
strcpy(fsn,"tmpsendfile.dat");
//printf("\n input dest address ip");
//scanf("%s",netaddr);
// strcpy(netaddr,"192.168.0.82");
f_in=BIO_new_file(fsn,"r");
if(f_in==NULL)
{
printf("open err!");return 0;
}
strcat(netaddr,":65531");
printf("\n Connecting to %s\n",netaddr);
n_out=BIO_new_connect(netaddr);
if(BIO_do_connect(n_out) <= 0)
{
printf( "Error connecting to server\n");
return 0;
}
else
{
printf("\nconnected!\n");
}
while(1)
{
len=BIO_read(f_in,buff,BUFFMAXSIZE);
if(len==0)
{
break;
}
BIO_write(n_out, buff,len);
// printf(" test code :%d ",n_out->retry_reason);
printf("\nsend %d kb\b",i);i++;
//printf("%d ",n_out->retry_reason);
// printf("%d size sent!\n",len);
}
printf("\nsend ok!");
BIO_free(n_out);
BIO_free(f_in);
}
else
{
//reciever
//printf("\ninput file name:");
//scanf("%s",frn);
strcpy(frn,"tmpgetfile.dat");
f_out=BIO_new_file(frn,"w");
if(f_out==NULL)
{
printf("open error!");
}
sock=BIO_get_accept_socket("65531",0);
n_in=BIO_new_socket(sock, BIO_CLOSE);
//printf("\nstart listening\n");
ret=BIO_accept(sock,NULL);
//printf("start recieve\n");
BIO_set_fd(n_in,ret,BIO_CLOSE);
while(1)
{
len = BIO_read(n_in, buff, BUFFMAXSIZE);
if(len==0 || len==-1) { BIO_free(n_in); goto outline;}
// printf("\n%d size recieved",len);
// printf(" test code :%d ",n_in->retry_reason);
printf("recieve %d kb\b",i);i++;
BIO_write(f_out,buff,len);
}
outline:
BIO_free(f_out);
printf("\n recieve OK!");
}
return 0;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -