Changeset 6c92572 in network-game for client/Client/main.cpp


Ignore:
Timestamp:
Nov 23, 2012, 9:05:22 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
cb1f288
Parents:
e084950
Message:

The client now keeps sending messages until the user quits

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    re084950 r6c92572  
    6363        memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
    6464        server.sin_port = htons(atoi(argv[2]));
    65         cout << "Please enter the message: ";
    66         cin.getline(msgTo.buffer, 256);
    67         socklen_t socklen = sizeof(server);
    6865
    69         n=sendMessage(&msgTo, sock, &server);
    70         if (n < 0)
    71                 error("sendMessage");
     66        while(true) {
     67                cout << "Please enter the message: ";
     68                cin.getline(msgTo.buffer, 256);
     69               
     70                if (strcmp(msgTo.buffer, "quit") == 0) {
     71                        break;
     72                }
    7273
    73         n = receiveMessage(&msgFrom, sock, &from);
    74         if (n < 0)
    75                 error("receiveMessage");
     74                socklen_t socklen = sizeof(server);
     75                n=sendMessage(&msgTo, sock, &server);
     76                if (n < 0)
     77                        error("sendMessage");
     78
     79                n = receiveMessage(&msgFrom, sock, &from);
     80                if (n < 0)
     81                        error("receiveMessage");
    7682       
    77         cout << "Got an ack: " << endl;
    78         cout << msgFrom.buffer << endl;
     83                cout << msgFrom.buffer << endl;
     84        }
     85
     86        cout << "Thank you for playing!" << endl;
    7987
    8088        closesocket(sock);
Note: See TracChangeset for help on using the changeset viewer.