⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filet.cpp

📁 这是RSA算法的原代码实现应该直接能用,已调试好
💻 CPP
字号:
/*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"

//文件的打开写入 传送……
 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;
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -