// // This program shows how to use the Middleware Service to send // data to another program. // // // The following Middle code was used as input to the Middleware // Service: // MsgManager // (vector, string) @msg_id_1 // (set) @msg_id_2 // } // // The output from the C++ Middleware Writer was stored in a // file called MsgManager.hh. // #include #include #include #include #include #include #include #include uint32_t msg_length_max = 20000; using namespace std; #include int main() try { int sockfd; sockaddr_in ambaddr; char hostname[100]; struct hostent* hostEnt; if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { cout << "Socket call failed with errno " << errno << "\n"; return 0; } ambaddr.sin_family = AF_INET; ambaddr.sin_port = 12345; gethostname(hostname, sizeof(hostname)); if ((hostEnt = gethostbyname(hostname)) != NULL) { ambaddr.sin_addr = *(struct in_addr *)hostEnt->h_addr_list[0]; } else { cout << "Gethostbyname() failed with errno of " << errno << "\n"; return 0; } if (connect(sockfd, (struct sockaddr*) &ambaddr, sizeof(ambaddr)) < 0) { cout << "Connect call failed with errno of " << errno << ".\n"; return 0; } auto_ptr buffer(new SendCompressedBuffer(4096)); buffer->sock_ = sockfd; string s = "Proverbs 24:27"; vector ivec; set iset; for (int j = 40; j < 100; j += 3) { ivec.push_back(j); iset.insert(j*2); } cout << "Enter the ID of the message you want to send: 1 or 2." << endl; int msgID; cin >> msgID; switch (msgID) { case 1: MsgManager::Send(buffer.get(), ivec, s); break; case 2: MsgManager::Send(buffer.get(), iset); break; default: cout << "Unexpected msg id.\n" << flush; } close(sockfd); return 1; } catch (failure const& ex) { cout << "failure: " << ex.what() << endl; }