-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_client_main.cpp
64 lines (56 loc) · 1.39 KB
/
simple_client_main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "ClientSocket.h"
#include "SocketException.h"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
vector<string> split(const string& s, const string& delim, const bool keep_empty = true) {
vector<string> result;
if (delim.empty()) {
result.push_back(s);
return result;
}
string::const_iterator substart = s.begin(), subend;
while (true) {
subend = search(substart, s.end(), delim.begin(), delim.end());
string temp(substart, subend);
if (keep_empty || !temp.empty()) {
result.push_back(temp);
}
if (subend == s.end()) {
break;
}
substart = subend + delim.size();
}
return result;
}
int main(int argc, int argv[]) {
try {
ClientSocket client_socket("localhost", 30000);
std::string reply,output;
try {
client_socket << "Test message.";
client_socket >> reply;
} catch (SocketException&) {
}
//cout << reply;
std::vector<std::string> arr;
arr = split(reply, ",");
for (size_t i = 0; i < arr.size(); i++){
std::string token=arr[i].c_str();
//std::cout << output;
if(token=="--"){
output+="\n";
std::cout << output;
}else{
output+="\t"+token;
}
}
;
} catch (SocketException& e) {
std::cout << "Exception was caught:" << e.description() << "\n";
}
return 0;
}