亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? transferfunctions.cpp

?? <Visual C++ 網絡程序設計實例詳解>配套源碼
?? CPP
字號:

#define PRE_AGREED_PORT		8686
#define SEND_BUFFER_SIZE	4096


BOOL CYourServerClass::SendFileToRemoteRecipient(CString fName)
{
	/***************************
	// listens for a connection from a remote client and uploads a file to it
	// the remote client must be running a counterpart GetFileFromRemoteSender function
	// Input: CString fName = name of local file which will be uploaded to remote client
	// Output: BOOL return value indicates success or failure of the upload
	***************************/
	
	// create socket and listen on pre-designated port

///	AfxSocketInit(NULL);	// make certain this is done somewhere in each thread (usually in InitInstance for main thread)
	CSocket sockSrvr; 
	sockSrvr.Create(PRE_AGREED_PORT);	// Creates our server socket
	sockSrvr.Listen();					// Start listening for the client at PORT
	CSocket sockConnection;
	sockSrvr.Accept(sockConnection);	// Use another CSocket to accept the connection
	
	// local variables used in file transfer (declared here to avoid "goto skips definition"-style compiler errors)

	BOOL bRet = TRUE;				// return value

	int fileLength, cbLeftToSend;	// used to monitor the progress of a sending operation
	
	BYTE* sendData = NULL;			// pointer to buffer for sending data (memory is allocated after sending file size)
	
	CFile sourceFile;
	CFileException fe;
	BOOL bFileIsOpen = FALSE;
	
	if( !( bFileIsOpen = sourceFile.Open( fName, CFile::modeRead | CFile::typeBinary, &fe ) ) )
	{
		TCHAR strCause[256];
		fe.GetErrorMessage( strCause, 255 );
		TRACE( "SendFileToRemoteRecipient encountered an error while opening the local file\n"
			"\tFile name = %s\n\tCause = %s\n\tm_cause = %d\n\tm_IOsError = %d\n",
			fe.m_strFileName, strCause, fe.m_cause, fe.m_lOsError );
		
		/* you should handle the error here */
		
		bRet = FALSE;
		goto PreReturnCleanup;
	}
	

	// first send length of file
	
	fileLength = sourceFile.GetLength();
	fileLength = htonl( fileLength );
	
	cbLeftToSend = sizeof( fileLength );
	
	do
	{
		int cbBytesSent;
		BYTE* bp = (BYTE*)(&fileLength) + sizeof(fileLength) - cbLeftToSend;
		cbBytesSent = sockConnection.Send( bp, cbLeftToSend );
		
		// test for errors and get out if they occurred
		if ( cbBytesSent == SOCKET_ERROR )
		{
			int iErr = ::GetLastError();
			TRACE( "SendFileToRemoteRecipient returned a socket error while sending file length\n"
				"\tNumber of Bytes sent = %d\n"
				"\tGetLastError = %d\n", cbBytesSent, iErr );
			
			/* you should handle the error here */

			bRet = FALSE;
			goto PreReturnCleanup;
		}
		
		// data was successfully sent, so account for it with already-sent data
		cbLeftToSend -= cbBytesSent;
	}
	while ( cbLeftToSend>0 );
	
	
	// now send the file's data
	
	sendData = new BYTE[SEND_BUFFER_SIZE]; 
	
	cbLeftToSend = sourceFile.GetLength();
	
	do
	{
		// read next chunk of SEND_BUFFER_SIZE bytes from file
		
		int sendThisTime, doneSoFar, buffOffset;
		
		sendThisTime = sourceFile.Read( sendData, SEND_BUFFER_SIZE );
		buffOffset = 0;
		
		do
		{
			doneSoFar = sockConnection.Send( sendData + buffOffset, sendThisTime ); 
			
			// test for errors and get out if they occurred
			if ( doneSoFar == SOCKET_ERROR )
			{
				int iErr = ::GetLastError();
				TRACE( "SendFileToRemoteRecipient returned a socket error while sending chunked file data\n"
					"\tNumber of Bytes sent = %d\n"
					"\tGetLastError = %d\n", doneSoFar, iErr );
				
				/* you should handle the error here */
				
				bRet = FALSE;
				goto PreReturnCleanup;
			}
			
/***************************
  un-comment this code and put a breakpoint here to prove to yourself that sockets can send fewer bytes than requested
			  
			if ( doneSoFar != sendThisTime )
			{
				int ii = 0;
			}
****************************/
			
			// data was successfully sent, so account for it with already-sent data
			
			buffOffset += doneSoFar;
			sendThisTime -= doneSoFar;
			cbLeftToSend -= doneSoFar;
		}
		while ( sendThisTime > 0 );
		
	}
	while ( cbLeftToSend > 0 );
	
	
PreReturnCleanup:		// labelled goto destination
	
	// free allocated memory
	// if we got here from a goto that skipped allocation, delete of NULL pointer
	// is permissible under C++ standard and is harmless
	delete[] sendData;
	
	if ( bFileIsOpen )
		sourceFile.Close();		// only close file if it's open (open might have failed above)
	
	sockConnection.Close();
	
	return bRet;
	
}




#define PRE_AGREED_PORT		8686
#define RECV_BUFFER_SIZE	4096

BOOL CYourClientClass::GetFileFromRemoteSender(CString strIP, CString fName)
{
	/***************************
	// connects to a remote server and downloads a file from it
	// the remote server must be running a counterpart SendFileToRemoteRecipient function
	// Inputs: CString strIP = IP address of remote server, in dotted IP format (like "127.0.0.1") or a manchine name (like "localhost")
	//         CString fName = name of local file to which downlaoded data will be stored
	// Output: BOOL return value indiactes success or failure of the download
	****************************/

	// create client socket and connect to server
	
///	AfxSocketInit(NULL);	// make certain this is done somewhere in each thread (usually in InitInstance for main thread)
	CSocket sockClient;
	sockClient.Create();
	
	sockClient.Connect( strIP, PRE_AGREED_PORT );	// PRE_AGREED_PORT is #define'd as 8686
	
	
	// local variables used in file transfer (declared here to avoid "goto skips definition"-style compiler errors)
	
	BOOL bRet = TRUE;								// return value
	
	int dataLength, cbBytesRet, cbLeftToReceive;	// used to monitor the progress of a receive operation
	
	BYTE* recdData = NULL;	// pointer to buffer for receiving data (memory is allocated after obtaining file size)
	
	CFile destFile;
	CFileException fe;
	BOOL bFileIsOpen = FALSE;
	
	// open/create target file that receives the transferred data
	
	if( !( bFileIsOpen = destFile.Open( fName, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary, &fe ) ) )
	{
		TCHAR strCause[256];
		fe.GetErrorMessage( strCause, 255 );
		TRACE( "GetFileFromRemoteSender encountered an error while opening the local file\n"
			"\tFile name = %s\n\tCause = %s\n\tm_cause = %d\n\tm_IOsError = %d\n",
			fe.m_strFileName, strCause, fe.m_cause, fe.m_lOsError );
		
		/* you should handle the error here */
		
		bRet = FALSE;
		goto PreReturnCleanup;
	}
	
	
	// get the file's size first
	
	cbLeftToReceive = sizeof( dataLength );
	
	do
	{
		BYTE* bp = (BYTE*)(&dataLength) + sizeof(dataLength) - cbLeftToReceive;
		cbBytesRet = sockClient.Receive( bp, cbLeftToReceive );
		
		// test for errors and get out if they occurred
		if ( cbBytesRet == SOCKET_ERROR || cbBytesRet == 0 )
		{
			int iErr = ::GetLastError();
			TRACE( "GetFileFromRemoteSite returned a socket error while getting file length\n"
				"\tNumber of Bytes received (zero means connection was closed) = %d\n"
				"\tGetLastError = %d\n", cbBytesRet, iErr );
			
			/* you should handle the error here */
			
			bRet = FALSE;
			goto PreReturnCleanup;
		}
		
		// good data was retrieved, so accumulate it with already-received data
		cbLeftToReceive -= cbBytesRet;
		
	}
	while ( cbLeftToReceive > 0 );
	
	dataLength = ntohl( dataLength );
	
	
	// now get the file in RECV_BUFFER_SIZE chunks at a time
	
	recdData = new byte[RECV_BUFFER_SIZE];
	cbLeftToReceive = dataLength;
	
	do
	{	
		int iiGet, iiRecd;
		
		iiGet = (cbLeftToReceive<RECV_BUFFER_SIZE) ? cbLeftToReceive : RECV_BUFFER_SIZE ;
		iiRecd = sockClient.Receive( recdData, iiGet );
		
		// test for errors and get out if they occurred
		if ( iiRecd == SOCKET_ERROR || iiRecd == 0 )
		{
			int iErr = ::GetLastError();
			TRACE( "GetFileFromRemoteSite returned a socket error while getting chunked file data\n"
				"\tNumber of Bytes received (zero means connection was closed) = %d\n"
				"\tGetLastError = %d\n", iiRecd, iErr );
			
			/* you should handle the error here */
			
			bRet = FALSE;
			goto PreReturnCleanup;
		}

/*************************	
  un-comment this code and put a breakpoint here to prove to yourself that sockets can return fewer bytes than requested
		  
			if ( iiGet != iiRecd )
			{
			int ii=0;
			}			
***************************/
		
		// good data was retrieved, so accumulate it with already-received data
		
		destFile.Write( recdData, iiRecd); // Write it
		cbLeftToReceive -= iiRecd;
		
	} 
	while ( cbLeftToReceive > 0 );
	
	
PreReturnCleanup:		// labelled "goto" destination
	
	// free allocated memory
	// if we got here from a goto that skipped allocation, delete of NULL pointer
	// is permissible under C++ standard and is harmless
	delete[] recdData;		
	
	if ( bFileIsOpen )
		destFile.Close();	// only close file if it's open (open might have failed above)
	
	sockClient.Close();
	
	return bRet;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
怡红院av一区二区三区| 国产一区二区三区黄视频 | 91在线高清观看| 日精品一区二区| 中文字幕一区二区三| 日韩女优制服丝袜电影| 色综合天天综合网国产成人综合天| 麻豆一区二区三| 一区二区成人在线视频| 国产日产欧美精品一区二区三区| 欧美精品九九99久久| 91玉足脚交白嫩脚丫在线播放| 国产在线视视频有精品| 亚洲成人高清在线| 亚洲三级在线免费| 精品成人免费观看| 欧美日韩国产在线播放网站| av激情综合网| 成人午夜精品一区二区三区| 激情图区综合网| 奇米888四色在线精品| 亚洲国产va精品久久久不卡综合| 国产精品久久久久久久浪潮网站 | 亚洲欧美日韩一区二区 | 国产91对白在线观看九色| 视频在线观看一区二区三区| 一区二区三区精品在线观看| 国产精品久久久久影院亚瑟 | 日本一区二区三区久久久久久久久不 | 欧美日韩成人在线| 97精品视频在线观看自产线路二| 国产成人精品免费网站| 国产精品一二一区| 国产在线播精品第三| 美女一区二区三区| 蜜桃视频第一区免费观看| 午夜欧美视频在线观看| 亚洲成人黄色影院| 日韩精品一级二级| 天堂蜜桃一区二区三区| 午夜精品久久久久久久99水蜜桃| 一区二区免费看| 亚洲线精品一区二区三区| 亚洲综合色婷婷| 亚洲地区一二三色| 青青草原综合久久大伊人精品| 日韩经典中文字幕一区| 免费成人深夜小野草| 精品影院一区二区久久久| 国内外成人在线| 国产福利一区在线| www.欧美日韩| 欧美在线999| 欧美日韩国产在线观看| 日韩视频国产视频| 久久天天做天天爱综合色| 国产午夜亚洲精品羞羞网站| 中文字幕在线一区二区三区| 亚洲色图制服诱惑 | 亚洲午夜精品在线| 日韩中文字幕av电影| 久久精品国产亚洲一区二区三区 | 成人午夜在线播放| 成人激情免费网站| 91久久精品国产91性色tv| 欧美日韩一级二级三级| 日韩欧美国产三级| 国产三级久久久| 亚洲国产你懂的| 久久国产精品无码网站| 成人激情午夜影院| 欧美剧在线免费观看网站| 精品福利一二区| 亚洲色图制服诱惑| 六月丁香综合在线视频| 成人激情免费电影网址| 7878成人国产在线观看| 久久久久成人黄色影片| 亚洲综合一区二区精品导航| 精品一区二区三区香蕉蜜桃| 成人av小说网| 欧美一区二视频| 国产精品乱人伦中文| 视频在线观看一区二区三区| 成人国产电影网| 欧美一级在线观看| 亚洲欧美一区二区三区国产精品| 肉色丝袜一区二区| 91免费看片在线观看| 日韩女优制服丝袜电影| 一二三区精品视频| 国产麻豆午夜三级精品| 欧美日韩中文精品| 中文字幕亚洲一区二区av在线| 蜜臀av国产精品久久久久| 一本色道久久综合亚洲91 | 3751色影院一区二区三区| 日本一区二区成人在线| 免费成人在线观看| 欧美三级电影网| 一区在线播放视频| 国产中文一区二区三区| 欧美日韩亚洲综合| 成人欧美一区二区三区白人| 精品中文av资源站在线观看| 欧美日韩卡一卡二| 亚洲婷婷在线视频| 国产精品一二三四| 精品三级在线看| 天堂成人国产精品一区| 91麻豆国产福利精品| 国产精品视频第一区| 激情综合色综合久久综合| 欧美日韩亚洲高清一区二区| 一区二区在线观看免费视频播放| 成人av网站在线| 国产三级精品在线| 国产乱人伦精品一区二区在线观看| 欧美精品免费视频| 夜夜精品视频一区二区| 色综合中文字幕| 亚洲色图在线视频| 91免费视频网| 亚洲日本韩国一区| 91亚洲精品久久久蜜桃网站| 国产日韩一级二级三级| 国产成人亚洲综合a∨猫咪| 2021中文字幕一区亚洲| 国内不卡的二区三区中文字幕 | 成人中文字幕合集| 久久欧美一区二区| 韩国在线一区二区| 欧美精品一区二| 国产自产高清不卡| 久久久亚洲欧洲日产国码αv| 国内精品视频666| 久久日韩精品一区二区五区| 久久福利资源站| 久久久亚洲高清| 粉嫩av一区二区三区在线播放| 国产视频一区在线观看 | 东方aⅴ免费观看久久av| 日韩女优视频免费观看| 国产在线精品一区在线观看麻豆| 欧美v日韩v国产v| 国产一区激情在线| 国产精品视频第一区| 91浏览器在线视频| 午夜国产精品一区| 欧美不卡一区二区三区四区| 激情国产一区二区| 国产精品入口麻豆原神| 99在线热播精品免费| 一区二区在线看| 91精品国产品国语在线不卡| 极品少妇一区二区| 国产精品私人自拍| 色欧美片视频在线观看| 午夜精品福利视频网站| 日韩欧美一区二区不卡| 丰满白嫩尤物一区二区| 一区二区视频在线看| 欧美群妇大交群中文字幕| 国产在线精品一区二区夜色| 国产精品色在线观看| 欧美亚洲综合色| 久久av资源网| 国产精品久久久久aaaa| 欧美日韩在线三级| 国产麻豆精品在线| 一区二区三区四区亚洲| 欧美一级黄色大片| 不卡av在线免费观看| 亚洲国产成人va在线观看天堂| 精品日韩欧美一区二区| 97精品久久久午夜一区二区三区| 天天综合天天做天天综合| 国产欧美精品一区二区色综合 | 91国产免费观看| 麻豆精品蜜桃视频网站| 国产精品免费视频观看| 欧美日韩国产不卡| 国产精品自拍网站| 亚洲一区二区三区自拍| 久久日韩精品一区二区五区| 欧美性猛交xxxx黑人交| 国产伦精品一区二区三区免费 | 精品成人a区在线观看| 99久久婷婷国产精品综合| 免费精品视频在线| 亚洲三级在线观看| 26uuu另类欧美| 欧美午夜精品电影| 国产不卡视频在线观看| 蜜桃视频在线一区| 亚洲激情综合网| 欧美激情资源网| 欧美精品一区二区三区蜜臀| 欧美日韩一区视频| 97精品国产97久久久久久久久久久久|