-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.cpp
44 lines (37 loc) · 1.11 KB
/
client_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include "Client.h"
#include <thread>
#include <chrono>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[]) {
try {
if (argc != 3) {
cout << "Error wrong arg count. Please enter the ./client HOST PORT." << endl;
return 0;
}
Client client(argv[1], atoi(argv[2]));
string input;
// Read line from user
getline(cin, input);
while (!input.empty()) {
// Send line via socket
client << input;
// Receive response
string response, tmpResponse;
int status = client.socket.receive(response);
// Concat responses if the packet received has max length
while (status == MAX_RECEIVABLE_LENGTH) {
status = client.socket.receive(tmpResponse);
response += tmpResponse;
}
// Output response
cout << response << endl;
// Read another line from user
getline(cin, input);
}
} catch (SocketException &e) {
cout << "Caught: " << e << endl;
}
return 0;
}