Survey Client
#include <iostream>
#include <iomanip>
#include "PracticalSocket.h"
#include "SurveyCommon.h"
 
using namespace std;
 
int main(int argc, char *argv[]) {
    if (argc != 2) {
        cerr << "Usage: SurveyClient <Survey Server Host>" << endl;
        return 1;
    }
 
    try {
        TCPSocket sock(argv[1], SURVEY_PORT);
 
        int qCount = recvInt(&sock);
        for (int q = 0; q < qCount; q++) {
            cout << "Q" << q << ": " << recvString(&sock) << endl;
            int rCount = recvInt(&sock);
            for (int r = 0; r < rCount; r++) 
                cout << setw(2) << r << " " << recvString(&sock) << endl;
 
            int response = rCount;
            while (response < 0 || response >= rCount) {
                cout << "> ";
                cin >> response;
            }
 
            sendInt(&sock, response);
        }
    } catch (runtime_error &e) {
        cerr << e.what() << endl;
        return 1;
    }
 
    return 0;
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License