-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.cpp
37 lines (31 loc) · 1.07 KB
/
client.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
#include <atomic>
#include <iostream>
#include "WebSocketClient.h"
class Client : public poca_ws::WebSocketClientListener {
public:
virtual void OnBinary(uint8_t* data, int len) override {
std::cout << "Receive binary data, len: " << len << std::endl;
}
virtual void OnText(std::string& msg) override { std::cout << "OnText: " << msg << std::endl; };
virtual void OnClosed() override { std::cout << "OnClosed" << std::endl; }
void Run(std::string addr, int port) {
ws_client = new poca_ws::WebSocketClient(*this);
ws_client->Connect(addr, port);
std::string msg = std::string(20480, 'a');
for (int i = 0; i < 1000; ++i) {
msg += std::to_string(i);
ws_client->SendMessage(msg);
std::cout << i << std::endl;
}
usleep(500 * 1000);
ws_client->Disconnect();
usleep(500 * 1000);
}
poca_ws::WebSocketClient* ws_client;
};
int main(int argc, char* argv[]) {
Client c;
c.Run("127.0.0.1", 8080);
poca_ws::WebSocketClient::CloseAll();
return 0;
}