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

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

?? mysocket.cpp

?? socket 編程實例 singleServerMultipleClientSrc
?? CPP
?? 第 1 頁 / 共 3 頁
字號:
		errMsg.append("with the SO_BROADCAST parameter to allow the use of the broadcast address.");
	}
	else if ( *errCode == WSAEINTR )
	{
		errMsg.append("A blocking Windows Sockets 1.1 call was canceled\n");
		errMsg.append("through WSACancelBlockingCall.");
	}
	else if ( *errCode == WSAEINPROGRESS )
	{
		errMsg.append("A blocking Windows Sockets 1.1 call is in progress,\n");
		errMsg.append("or the service provider is still processing a callback function.");
	}
	else if ( *errCode == WSAEFAULT )
	{
		errMsg.append("The buf parameter is not completely contained in a\n");
		errMsg.append("valid part of the user address space.");
	}
	else if ( *errCode == WSAENETRESET )
	{
		errMsg.append("The connection has been broken due to the keep-alive\n");
		errMsg.append("activity detecting a failure while the operation was in progress.");
	}
	else if ( *errCode == WSAENOBUFS )
		errMsg.append("No buffer space is available.");
	else if ( *errCode == WSAENOTCONN )
		errMsg.append("The socket is not connected.");
	else if ( *errCode == WSAENOTSOCK )
		errMsg.append("The descriptor is not a socket.");
	else if ( *errCode == WSAEOPNOTSUPP )
	{
		errMsg.append("MSG_OOB was specified, but the socket is not stream-style\n");
		errMsg.append("such as type SOCK_STREAM, out-of-band data is not supported\n");
		errMsg.append("in the communication domain associated with this socket,\n");
		errMsg.append("or the socket is unidirectional and supports only receive operations.");
	}
	else if ( *errCode == WSAESHUTDOWN )
	{
		errMsg.append("The socket has been shut down; it is not possible to send\n");
		errMsg.append("on a socket after shutdown has been invoked with how set\n");
		errMsg.append("to SD_SEND or SD_BOTH.");
	}
	else if ( *errCode == WSAEWOULDBLOCK )
		errMsg.append("The socket is marked as nonblocking and the requested operation would block.\n");
	else if ( *errCode == WSAEMSGSIZE )
	{
		errMsg.append("The socket is message oriented, and the message is larger\n");
		errMsg.append("than the maximum supported by the underlying transport.");
	}
	else if ( *errCode == WSAEHOSTUNREACH )
		errMsg.append("The remote host cannot be reached from this host at this time.");
	else if ( *errCode == WSAEINVAL )
	{
		errMsg.append("The socket has not been bound with bind, or an unknown flag\n");
		errMsg.append("was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled.");
	}
	else if ( *errCode == WSAECONNABORTED )
	{
		errMsg.append("The virtual circuit was terminated due to a time-out or \n");
		errMsg.append("other failure. The application should close the socket as it is no longer usable.");
	}
	else if ( *errCode == WSAECONNRESET )
	{
		errMsg.append("The virtual circuit was reset by the remote side executing a \"hard\" \n");
		errMsg.append("or \"abortive\" close. For UPD sockets, the remote host was unable to\n");
		errMsg.append("deliver a previously sent UDP datagram and responded with a\n");
		errMsg.append("\"Port Unreachable\" ICMP packet. The application should close\n");
		errMsg.append("the socket as it is no longer usable.");
	}
	else if ( *errCode == WSAETIMEDOUT )
	{
		errMsg.append("The connection has been dropped, because of a network failure\n");
		errMsg.append("or because the system on the other end went down without notice.");
	}
	else errMsg.append("unknown problems!");
}

#endif

void myTcpSocket::connectToServer(string& serverNameOrAddr,hostType hType)
{ 
	/* 
	   when this method is called, a client socket has been built already,
	   so we have the socketId and portNumber ready.

       a myHostInfo instance is created, no matter how the server's name is 
	   given (such as www.yuchen.net) or the server's address is given (such
	   as 169.56.32.35), we can use this myHostInfo instance to get the 
	   IP address of the server
	*/

	myHostInfo serverInfo(serverNameOrAddr,hType);
	
    // Store the IP address and socket port number	
	struct sockaddr_in serverAddress;
    serverAddress.sin_family = AF_INET;
    serverAddress.sin_addr.s_addr = inet_addr(serverInfo.getHostIPAddress());
    serverAddress.sin_port = htons(portNumber);

    // Connect to the given address
	try 
	{
		if (connect(socketId,(struct sockaddr *)&serverAddress,sizeof(serverAddress)) == -1)
		{
			#ifdef WINDOWS_XP
				int errorCode = 0;
				string errorMsg = "error calling connect():\n";
				detectErrorConnect(&errorCode,errorMsg);
				myException socketConnectException(errorCode,errorMsg);
				throw socketConnectException;
			#endif

			#ifdef UNIX
				myException unixSocketConnectException(0,"unix: error calling connect()");
				throw unixSocketConnectException;
			#endif
        }
	}
    catch(myException& excp)
	{
		excp.response();
		exit(1);
	}
}

myTcpSocket* myTcpSocket::acceptClient(string& clientHost)
{
	int newSocket;   // the new socket file descriptor returned by the accept systme call

    // the length of the client's address
    int clientAddressLen = sizeof(struct sockaddr_in);
    struct sockaddr_in clientAddress;    // Address of the client that sent data

    // Accepts a new client connection and stores its socket file descriptor
	try 
	{
		if ((newSocket = accept(socketId, (struct sockaddr *)&clientAddress,&clientAddressLen)) == -1)
		{
			#ifdef WINDOWS_XP
				int errorCode = 0;
				string errorMsg = "error calling accept(): \n";
				detectErrorAccept(&errorCode,errorMsg);
				myException socketAcceptException(errorCode,errorMsg);
				throw socketAcceptException;
			#endif

			#ifdef UNIX
				myException unixSocketAcceptException(0,"unix: error calling accept()");
				throw unixSocketAcceptException;
			#endif
        }
	}
    catch(myException& excp)
	{
		excp.response();
		return NULL;
	}
    
	// Get the host name given the address
    char *sAddress = inet_ntoa((struct in_addr)clientAddress.sin_addr);
	myHostInfo clientInfo(string(sAddress),ADDRESS);
	char* hostName = clientInfo.getHostName();
    clientHost += string(hostName);
	
    // Create and return the new myTcpSocket object
    myTcpSocket* retSocket = new myTcpSocket();
	retSocket->setSocketId(newSocket);
    return retSocket;
}

void myTcpSocket::listenToClient(int totalNumPorts)
{
	try 
	{
		if (listen(socketId,totalNumPorts) == -1)
		{
			#ifdef WINDOWS_XP
				int errorCode = 0;
				string errorMsg = "error calling listen():\n";
				detectErrorListen(&errorCode,errorMsg);
				myException socketListenException(errorCode,errorMsg);
				throw socketListenException;
			#endif

			#ifdef UNIX
				myException unixSocketListenException(0,"unix: error calling listen()");
				throw unixSocketListenException;
			#endif
        }
	}
    catch(myException& excp)
	{
		excp.response();
		exit(1);
	}
}       

/*
int myTcpSocket::sendMessage(string& message)
{
	int numBytes;  // the number of bytes sent


	char msgLength[MSG_HEADER_LEN+1];
    sprintf(msgLength,"%6d",message.size());
	string sendMsg = string(msgLength);
    sendMsg += message;

	// Sends the message to the connected host
	try 
	{
		if (numBytes = send(socketId,sendMsg.c_str(),sendMsg.size(),0) == -1)
		{
			#ifdef WINDOWS_XP
				int errorCode = 0;
				string errorMsg = "error calling send():\n";
				detectErrorSend(&errorCode,errorMsg);
				myException socketSendException = new myException(errorCode,errorMsg);
				throw socketSendException;
			#endif

			#ifdef UNIX
				myException unixSocketSendException = new myException(0,"unix: error calling send()");
				throw unixSocketSendException;
			#endif
        }
	}
    catch(myException& excp)
	{
		excp.response();
		exit(1);
	}

	return numBytes;
}
*/
int myTcpSocket::sendMessage(string& message)
{
	int numBytes;  // the number of bytes sent

	/* 
	   for each message to be sent, add a header which shows how long this message
	   is. This header, regardless how long the real message is, will always be
	   of the length MSG_HEADER_LEN.
	*/

	char msgLength[MSG_HEADER_LEN+1];
    sprintf(msgLength,"%6d",message.size());
	string sendMsg = string(msgLength);
    sendMsg += message;

	// Sends the message to the connected host
	try 
	{
		if (numBytes = send(socketId,sendMsg.c_str(),sendMsg.size(),0) == -1)
		{
			#ifdef WINDOWS_XP
				int errorCode = 0;
				string errorMsg = "error calling send():\n";
				detectErrorSend(&errorCode,errorMsg);
				myException socketSendException(errorCode,errorMsg);
				throw socketSendException;
			#endif

			#ifdef UNIX
				myException unixSocketSendException(0,"unix: error calling send()");
				throw unixSocketSendException;
			#endif
        }
	}
    catch(myException& excp)
	{
		excp.response();
		exit(1);
	}

	return numBytes;
}

#ifdef WINDOWS_XP
/*
int myTcpSocket::XPrecieveMessage(string& message)
{
	int numBytes = 0;                 // The number of bytes received
    int currentSize = MSG_HEADER_LEN; // The number of bytes wanted to receive
    int offsetSize = 0;               // The number of bytes currently recieved

	// retrieve the length of the message received

	char msgLength[MSG_HEADER_LEN+1];
	memset(msgLength,0,sizeof(msgLength));

	try
	{
		while ( numBytes < currentSize )
		{
			numBytes = recv(socketId,msgLength+offsetSize,currentSize,MSG_PEEK);
			if (numBytes == -1)
			{
				int errorCode = 0;
				string errorMsg = "error calling recv():\n";
				detectErrorRecv(&errorCode,errorMsg);
				myException socketRecvException = new myException(errorCode,errorMsg);
				throw socketRecvException;
			}
			else if ( numBytes < currentSize )
			{
				offsetSize += numBytes;
				currentSize -= numBytes;
			}
		}

	}
	catch(myException excp)
	{
		excp.response();
		exit(1);
	}

	// recieve the real message
	currentSize = atoi(msgLength);
	offsetSize = 0;

	cout   << "[RECV:message length] " << msgLength << endl;
	winLog << "[RECV:message length] " << msgLength << endl;

	try
	{
		while ( numBytes < currentSize )
		{
			numBytes = recv(socketId,(char*)(message.c_str())+offsetSize,currentSize,0);
			if (numBytes == -1)
			{
				int errorCode = 0;
				string errorMsg = "error calling recv():\n";
				detectErrorRecv(&errorCode,errorMsg);
				myException socketRecvException = new myException(errorCode,errorMsg);
				throw socketRecvException;
			}
			else if ( numBytes < currentSize )
			{
				offsetSize += numBytes;
				currentSize -= numBytes;
			}
		}

	}
	catch(myException& excp)
	{
		excp.response();
		exit(1);
	}

	cout   << "[RECV:message] " << message << endl;
	winLog << "[RECV:message] " << message << endl;

    return atoi(msgLength);   
}
*/


int myTcpSocket::XPrecieveMessage(string& message)
{
	int received = 0;                 // The number of bytes received
    int msgSize = MAX_RECV_LEN;       // The number of bytes wanted to receive
    int numBytes = 0;                 // The number of bytes currently recieved
	int totalRecvNum = 0;
	bool headerFinished = false;

	char charMsg[MAX_RECV_LEN+1];
	char msgLength[MSG_HEADER_LEN+1];
	memset(charMsg,0,sizeof(charMsg));
	memset(msgLength,0,sizeof(msgLength));

	try
	{
		while ( received < msgSize )
		{
			numBytes = recv(socketId,charMsg+received,1,0);
			if (numBytes == -1)
			{
				int errorCode = 0;
				string errorMsg = "error calling recv():\n";
				detectErrorRecv(&errorCode,errorMsg);
				myException socketRecvException(errorCode,errorMsg);
				throw socketRecvException;
			}

			if ( !headerFinished )
			{
				msgLength[received] = *(charMsg+received);
				received ++;

				if ( received == MSG_HEADER_LEN )
				{
					headerFinished = true;
					received = 0;
					memset(charMsg,0,sizeof(charMsg));
					msgSize = atoi(msgLength);
				}
			}
			else 
				received ++;
		}
	}
	catch(myException& excp)
	{
		if ( excp.getErrCode() == WSAECONNRESET )
		{
			//cout   << "!! your party has shut down the connection... \n";
			//winLog << "!! your party has shut down the connection... \n";
			return -99;
		}
		excp.response();
		exit(1);
	}

	message.append(string(charMsg));
    return msgSize;
}

#endif

int myTcpSocket::recieveMessage(string& message)
{
	int numBytes;  // The number of bytes recieved

	#ifdef WINDOWS_XP
		return XPrecieveMessage(message);
	#endif

	// retrieve the length of the message received

	char msgLength[MSG_HEADER_LEN+1];
	memset(msgLength,0,sizeof(msgLength));
	try
	{
		numBytes = recv(socketId,msgLength,MSG_HEADER_LEN,0);
        if (numBytes == -1)
        {
			myException unixSocketRecvException(0,"unix: error calling recv()");
			throw unixSocketRecvException;
		}
	}
    catch(myException& excp)
	{
		excp.response();
		exit(1);
	}

	// receive the real message
	try
	{
		numBytes = recv(socketId,(char*)(message.c_str()),atoi(msgLength),0);
        if (numBytes == -1)
        {
			myException unixSocketRecvException(0,"unix: error calling recv()");
			throw unixSocketRecvException;
		}
	}
    catch(myException& excp)
	{
		excp.response();
		exit(1);
	}

    return numBytes;
}


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产在线精品免费av| 亚洲激情六月丁香| 亚洲欧美精品午睡沙发| 丝袜脚交一区二区| 成人黄色国产精品网站大全在线免费观看| 色综合天天综合色综合av| 日韩精品一区二区三区在线播放 | 亚洲成人综合视频| 成人免费观看男女羞羞视频| 51精品久久久久久久蜜臀| 国产精品麻豆99久久久久久| 麻豆国产精品视频| 欧美日韩精品免费| 一区二区三区四区在线播放 | 蜜臀av在线播放一区二区三区| 99精品视频在线免费观看| 久久久蜜桃精品| 久久精工是国产品牌吗| 欧美日韩一区 二区 三区 久久精品| 久久精品在线观看| 国产一区在线视频| 欧美成人性福生活免费看| 亚洲五月六月丁香激情| 91玉足脚交白嫩脚丫在线播放| 久久久久久日产精品| 久久精品国产精品青草| 欧美疯狂性受xxxxx喷水图片| 亚洲色图19p| 99精品视频一区二区三区| 国产亚洲视频系列| 国产精品123| 久久精品无码一区二区三区| 蜜桃av一区二区| 日韩一区二区三区在线| 五月婷婷久久丁香| 91成人国产精品| 亚洲免费资源在线播放| 色网综合在线观看| 一区二区三区四区激情| 91国偷自产一区二区开放时间| 中文字幕一区二区三区av| 成人a免费在线看| 国产精品初高中害羞小美女文| 粉嫩aⅴ一区二区三区四区五区| 久久久久久久综合狠狠综合| 九九**精品视频免费播放| 欧美mv日韩mv| 国产中文字幕一区| 国产精品麻豆一区二区| 色综合久久久久综合体| 夜夜操天天操亚洲| 欧美日本一区二区| 久久99热国产| 国产精品久久久久久久久免费桃花| 北条麻妃国产九九精品视频| 亚洲精品中文字幕乱码三区| 91片黄在线观看| 亚洲另类春色校园小说| 欧美日韩国产一级二级| 美女视频黄 久久| 国产亚洲人成网站| 91久久精品网| 另类专区欧美蜜桃臀第一页| 国产丝袜在线精品| 色视频成人在线观看免| 日韩成人午夜精品| 国产欧美视频一区二区三区| 在线国产亚洲欧美| 精品一二线国产| 亚洲日本免费电影| 日韩三级电影网址| av综合在线播放| 免费av网站大全久久| 中文字幕高清一区| 欧美人与性动xxxx| 国产成人h网站| 午夜日韩在线观看| 欧美国产一区二区在线观看| 欧美日本韩国一区二区三区视频| 韩国女主播成人在线观看| 亚洲免费看黄网站| 久久久电影一区二区三区| 欧美在线看片a免费观看| 国产一区二区主播在线| 亚洲影视在线播放| 中文字幕第一区二区| 91精品黄色片免费大全| 99久久99久久综合| 国产精品一级片在线观看| 亚洲综合小说图片| 国产精品卡一卡二卡三| 亚洲精品一区二区在线观看| 欧美在线不卡一区| 国产 日韩 欧美大片| 日本不卡视频在线| 亚洲成a人v欧美综合天堂| 日韩久久一区二区| 国产亚洲婷婷免费| 亚洲精品一区二区三区蜜桃下载| 欧美丝袜丝nylons| 91视频国产资源| 国产成人精品三级麻豆| 日本成人超碰在线观看| 亚洲综合久久av| 亚洲人成网站影音先锋播放| 国产日产欧美一区| 久久众筹精品私拍模特| 日韩久久精品一区| 51久久夜色精品国产麻豆| 欧美亚洲国产一卡| 在线精品视频免费观看| 91麻豆高清视频| 91视视频在线观看入口直接观看www | 色综合亚洲欧洲| 成人av资源在线观看| 国产一区二区不卡老阿姨| 精东粉嫩av免费一区二区三区| 麻豆成人免费电影| 久久aⅴ国产欧美74aaa| 精品一区二区三区影院在线午夜| 日韩成人免费电影| 美女视频免费一区| 国产一区欧美日韩| 国产高清不卡一区二区| 国产999精品久久| gogogo免费视频观看亚洲一| 成人看片黄a免费看在线| 成人av午夜影院| 99国产一区二区三精品乱码| av亚洲精华国产精华精华 | 欧美午夜在线观看| 欧美日韩免费电影| 欧美sm美女调教| 久久这里只有精品6| 国产亚洲欧美在线| 亚洲精品一二三区| 亚洲成人一区在线| 国产曰批免费观看久久久| 成人综合婷婷国产精品久久| 99久久99久久综合| 91精品国产综合久久精品app| 91精品在线免费| 久久久久九九视频| 亚洲欧美日韩国产综合| 午夜电影一区二区三区| 精品在线免费视频| 99久久免费精品| 欧美另类高清zo欧美| 精品久久久久一区二区国产| 欧美激情综合网| 夜夜精品浪潮av一区二区三区| 蜜桃精品在线观看| 99精品国产热久久91蜜凸| 欧美精品在线视频| 国产视频一区在线观看| 亚洲一区二区美女| 国产乱码精品一区二区三区忘忧草 | 一区二区三区精品在线| 男女男精品网站| 99精品一区二区三区| 欧美一级一级性生活免费录像| 久久精品男人的天堂| 亚洲国产精品一区二区久久| 国产一区二区调教| 在线亚洲一区二区| 国产欧美日韩精品a在线观看| 怡红院av一区二区三区| 极品瑜伽女神91| 欧美日韩国产系列| 中文字幕一区免费在线观看| 美女免费视频一区二区| 欧美伊人久久久久久久久影院| 亚洲精品一区二区三区影院| 亚洲成人激情社区| 99国产精品99久久久久久| 欧美sm美女调教| 亚洲v中文字幕| 色女孩综合影院| 欧美高清在线一区| 久久国产精品第一页| 欧美日韩午夜在线| 亚洲欧洲制服丝袜| 成人激情免费网站| 欧美国产日韩亚洲一区| 青草av.久久免费一区| 欧美色图第一页| 亚洲天堂网中文字| 成人免费va视频| 国产日本一区二区| 国产精品夜夜嗨| 欧美mv日韩mv国产网站| 美女网站一区二区| 欧美一区二区成人| 丝袜亚洲另类欧美| 7777精品伊人久久久大香线蕉最新版| 亚洲免费av高清| 色综合久久久久久久| 亚洲视频中文字幕| 99久久国产综合色|国产精品| 国产精品丝袜在线|