// // 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, char*) @MSGID_1 // (set) @MSGID_2 // (unsigned int) @IN // } // // The output from the Middleware Service was stored in a // file called MsgManager.hh. // #include #include #include #include #include #include #include #include using namespace std; #include int main() { int sockfd; sockaddr_in ambaddr; char hostname[100]; struct hostent* hostEnt; MsgManager msg_manager; char s[40]; vector ivec; set iset; 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 Buffer(4096)); buffer->sock_ = sockfd; for (int j = 40; j < 100; j += 3) { ivec.push_back(j); iset.insert(j*2); } strcpy(s, "Proverbs 24:27"); cout << "Enter the ID of the message you want to send: 1 or 2." << endl; int msgID; cin >> msgID; switch (msgID) { case 1: if (!msg_manager.Send(buffer.get(), ivec, s)) { cout << "Send of MSGID_1 failed." << endl; } break; case 2: if (!msg_manager.Send(buffer.get(), iset)) { cout << "Send of MSGID_2 failed." << endl; } break; default: cout << "Unexpected MSG ID.\n" << flush; } close(sockfd); return 1; }