Ejemplo n.º 1
0
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();
    }
}
Ejemplo n.º 2
0
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();
	}
}
Ejemplo n.º 3
0
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;
		  foundIdx.push_back(id);
      frame.append(boost::lexical_cast<std::string>(id));
		  // ROS_INFO("id %s",frame);
      // std::cout << id << " " << frame << " ";
		}
Ejemplo n.º 4
0
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: "******"Input yout password: "******"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!")
						{
							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();
		}