当前位置: 首页>>代码示例>>C++>>正文


C++ TCP::CloseConnection方法代码示例

本文整理汇总了C++中TCP::CloseConnection方法的典型用法代码示例。如果您正苦于以下问题:C++ TCP::CloseConnection方法的具体用法?C++ TCP::CloseConnection怎么用?C++ TCP::CloseConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TCP的用法示例。


在下文中一共展示了TCP::CloseConnection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	
	TCP* tcp = new TCP();

	try
	{
		char chain[2104];
		string separtor = "";

		cout << "Input a chain of a numbers separated by spaces: ";
		cin.getline(chain, sizeof(chain));

		cout << "Input a separator: ";
		cin >> separtor;


		Send(tcp, chain);

		Send(tcp, separtor, false);

		cout << "Reseive: " << endl;
		cout << tcp->ReceiveData() << endl;
		tcp->CloseConnection();
	}
	catch (string error)
	{
		cout << error;
		tcp->CloseConnection();
	}
}
开发者ID:codeserfer,项目名称:7-term,代码行数:31,代码来源:2+-+client.cpp

示例2: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
    TCP* tcp = new TCP();

    try
    {
        tcp->Startup();
        tcp->InitSocket();
        tcp->Connect(PORT, HOST);

        cout << "Input string to send: ";

        string s;
        cin >> s;

        tcp->SendData(s);
        cout << "Reseive: " << endl;
        cout << tcp->ReceiveData() << endl;
        tcp->CloseConnection();
    }
    catch (string error)
    {
        cout << error;
        tcp->CloseConnection();
    }
}
开发者ID:codeserfer,项目名称:7-term,代码行数:26,代码来源:client.cpp

示例3: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	TCP* tcp = new TCP();

	try
	{
		tcp->Startup();
		tcp->InitSocket();
		tcp->Connect(PORT, HOST);



		tcp->SendData("HELO domain.local\r\n");
		cout << "Reseive: " << endl;
		cout << tcp->ReceiveData() << endl;

		tcp->SendData("MAIL FROM:<stud_08>\r\n");
		cout << "Reseive: " << endl;
		cout << tcp->ReceiveData() << endl;

		tcp->SendData("RCPT TO:<stud_07>\r\n");
		cout << "Reseive: " << endl;
		cout << tcp->ReceiveData() << endl;

		tcp->SendData("DATA\r\n");
		cout << "Reseive: " << endl;
		cout << tcp->ReceiveData() << endl;

		tcp->SendData("I want to sleep!\r\n.\r\n");
		cout << "Reseive: " << endl;
		cout << tcp->ReceiveData() << endl;

		tcp->SendData("QUIT\r\n");
		cout << "Reseive: " << endl;
		cout << tcp->ReceiveData() << endl;
		tcp->CloseConnection();
	}
	catch (string error)
	{
		cout << error;
		tcp->CloseConnection();
	}
}
开发者ID:codeserfer,项目名称:7-term,代码行数:43,代码来源:1.cpp

示例4: _tmain


//.........这里部分代码省略.........
					{
						throw Exception("Incorrect command. Correct your program's code!\n");
					}

					cout << endl;
					cout << DeleteLastLeter(ans) << endl;
					cout << endl;
				}
				// Game
				else if (s == "2")
				{
					tcp->SendData("GAME!");
					if ((ans = tcp->ReceiveDataExclamation()) == "ERROR!")
					{
						throw Exception("Incorrect command. Correct your program's code!\n");
					}

					int lettersCount = atoi(DeleteLastLeter(ans).c_str());

					cout << endl;
					cout << "The number of letters - " << lettersCount << endl;
					cout << endl;

					int mistakes = 0;
					string guessedWord(lettersCount, '-');
					

					cout << "Word: " << guessedWord << "\t" << "Count of mistakes: " << mistakes << "/6\n";

					while (true)
					{
						string letter;
						cout << "Input letter: ";
						cin >> letter;

						cout << "you has inputed: '" << letter << "'\n";

						if (letter.length() > 1)
							cout << "Your should input only one letter! Letter '" << letter.at(0) << "' has been sent.\n";

						// kostile
						string temp;
						temp.push_back(letter[0]);
						temp.push_back('!');
						//cout << "Sending letter '" << temp << "'\n";
						tcp->SendData(temp);
						if ((ans = tcp->ReceiveDataExclamation()) == "ERROR!")
						{
							throw Exception("Incorrect command. Correct your program's code!\n");
						}

						if (ans == "0!")
						{
							cout << "You win!\n";
							break;
						}
						else if (ans == "-1!")
						{
							cout << "This letter is absent\n";
							mistakes++;

							cout << "Word: " << guessedWord << "\t" << "Count of mistakes: " << mistakes << "/6\n";
						}
						else if (ans == "-2!")
						{
							cout << "Game over! You are lose.\n";
							break;
						}
						else
						{
							//cout << "Exists letters: " << ans << endl;

							auto ansVector = Split(ans, ',');
							for (int i = 0; i < ansVector.size(); i++)
							{
								int index = atoi(ansVector[i].c_str());
								guessedWord[index - 1] = letter.c_str()[0];
							}

							cout << guessedWord << endl;
						}
					}

				}
				else if (s == "EXIT!!!")
				{
					tcp->SendData(s);
					throw Exception("Hey, admin! Be kinder!");
				}
				// Something else?..
				else
				{
					cout << "Unrecognised command!\n";
				}
			}

			cout << "See your later!\n";
			tcp->SendData("Exit!");
			tcp->CloseConnection();
		}
开发者ID:codeserfer,项目名称:7-term,代码行数:101,代码来源:lab-client.cpp


注:本文中的TCP::CloseConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。