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


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

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


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

示例1: _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

示例2: _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

示例3: main

int main(int argc, char** argv)
{

  char port[] = "27015";
  char ip[] = "10.0.0.67";

  int numbytes;
  char buf[MAXDATASIZE];

  // Get input parameters
  for(int a=0; a < argc; a++)
    {
      if( strcmp( argv[a], "--ip" ) == 0 )
	{
	  strcpy(ip, argv[a+1]);
	}

      if( strcmp( argv[a], "--port" ) == 0 )
	{
	  strcpy(port, argv[a+1]);
	}
    }

  TCP myClient = TCP(port, ip);

  ros::init(argc, argv, "joints");
  ros::NodeHandle n;

  std::string receivedString;
  std::string attribute;
  std::stringstream ss;
  std::istringstream iss;

  tf::TransformBroadcaster br;
  tf::Transform transform;

  ros::Rate loop_rate(30);


  if( myClient.Connect() == 0 )
    {
      // Receive data
      numbytes = recv(myClient.s,buf,MAXDATASIZE-1,0);

      while (numbytes != 0 && ros::ok())
	{
	  numbytes = recv(myClient.s,buf,MAXDATASIZE-1,0);

	  buf[numbytes]='\0';

	  receivedString.assign(buf);

	  // debug
	  // std::cout << "Ahoy! Received " << numbytes << " bytes. " << receivedString << std::endl;

	  std::istringstream iss(receivedString);


	  std::vector<double> x (25, 0.0);
	  std::vector<double> y (25, 0.0);
	  std::vector<double> z (25, 0.0);

    std::vector<std::vector<double> > X (6, x);
    std::vector<std::vector<double> > Y (6, y);
    std::vector<std::vector<double> > Z (6, z);

    std::vector<double> qx (25, 0.0);
	  std::vector<double> qy (25, 0.0);
	  std::vector<double> qz (25, 0.0);
	  std::vector<double> qw (25, 1.0);

    std::vector<std::vector<double> > QX (6, qx);
    std::vector<std::vector<double> > QY (6, qy);
    std::vector<std::vector<double> > QZ (6, qz);
    std::vector<std::vector<double> > QW (6, qw);

	  int j;
	  int count = 6;
	  int id;

	  std::vector<int> foundIdx;
    std::string frame;
    std::string joint;

      /* code */

	  while(!iss.eof())
	    {
      // joint = "joint_";
      iss >> attribute;
      frame = "person_";

	      if( strcmp(attribute.c_str(), "count:") == 0 )
		{
		  iss >> count;
		  // ROS_INFO("count %d",count);
		}
	      else if( strcmp(attribute.c_str(), "id:") == 0 )
		{
		  iss >> id;
//.........这里部分代码省略.........
开发者ID:RIVeR-Lab,项目名称:fall_risk_assessment,代码行数:101,代码来源:joints.cpp

示例4: _tmain

int _tmain(int argc, _TCHAR* argv[])
{

	TCP* tcp = new TCP();

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

		//cout << "Sleep for 10 sec...\n";
		//Sleep(10 * 1000);
		//cout << "Wake up!\n";


		string login;
		cout << "Input yout login: ";
		cin >> login;

		string password;
		cout << "Input yout password: ";
		cin >> password;

		cout << "Hash is " << myhash(password) << endl;

		tcp->SendData(login + ":" + to_string(myhash(password)) + "!");
		string ans;
		if ((ans = tcp->ReceiveDataExclamation()) != "OK!")
			cout << "Incorrect login or password. Good bye.\n";
		else
		{
			while (true)
			{
				string s;

				cout << "0. Exit\n";
				cout << "1. Statistic\n";
				cout << "2. Start game\n";
				cin >> s;

				// Exit
				if (s == "0")
				{
					tcp->SendData("EXIT!");
					cout << "Server sent: " << tcp->ReceiveDataExclamation() << endl;
					break;
				}
				// Statistic
				else if (s == "1")
				{
					tcp->SendData("STATISTIC!");
					if ((ans = tcp->ReceiveDataExclamation()) == "ERROR!")
					{
						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!")
//.........这里部分代码省略.........
开发者ID:codeserfer,项目名称:7-term,代码行数:101,代码来源:lab-client.cpp


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