if we run the program for the gobbledygook.txt file after running the other python program trnslt2.py which has an output of ->
Enter a sentence: hola mi amigo come estas usted bien
Translation: gotteolgottaahgottuay gotteimgotteay gottoamgottoiggottuowgottoay gottuomgottiecgottoay gottoesgottitagottaswgottiay gottiusgottetegottedwgottuay gotteiegottunbgottaay
Translation saved to gobbledygook.txt
then what is the output and are there any errors?
#include
#include
#include
#include
#include
#include
#include
const int PORT = 8080;
std::string textToBinary(const std::string& text) {
std::string binaryCode;
for (char c : text) {
std::bitset<8> bits(c);
binaryCode += bits.to_string();
}
return binaryCode;
}
// int main() {
// std::string text;
// std::cout << "Entereth thine text: ";
// std::getline(std::cin >> std::ws, text);
int main() {
std::string text;
std::ifstream inputFile("gobbledygook.txt"); // Open the input file
if (inputFile.is_open()) {
std::getline(inputFile, text); // Read the contents of the file into the 'text' variable
inputFile.close(); // Close the input file
} else {
std::cerr << "Thy file requested hath not been retrieved, my liege." << std::endl;
return 1;
}
std::string binaryCode = textToBinary(text);
// Create a socket
int sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == -1) {
std::cerr << "My liege, we hath failed. " << std::endl;
return 1;
}
// Set up the server address
sockaddr_in serverAddress;
serverAddress.sin_family = AF_INET;
serverAddress.sin_port = htons(PORT);
std::string serverIP = "127.0.0.1"; // Default IP address
bool validIP = false;
while (!validIP) {
std::cout << "Entereth the receiver's IP address (default: 127.0.0.1): ";
std::cin >> serverIP;
if (inet_pton(AF_INET, serverIP.c_str(), &(serverAddress.sin_addr)) <= 0) {
std::cerr << "There appears to be no one home. Would you like to try again? (Yes/No): ";
std::string tryAgain;
std::cin >> tryAgain;
if (tryAgain != "Yes" && tryAgain != "yes" && tryAgain != "Y" && tryAgain != "y") {
return 1;
}
} else {
validIP = true;
}
}
// Connect to the server
if (connect(sock, reinterpret_cast
std::cerr << "Connection hath failed" << std::endl;
return 1;
}
// Send the binary code
if (send(sock, binaryCode.c_str(), binaryCode.size(), 0) < 0) {
std::cerr << "Failed to send data" << std::endl;
return 1;
}
// Close the socket
close(sock);
std::cout << "HAZAA!" << std::endl;
return 0;
}