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(); } }
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(); } }
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(); } }
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(); }