|
|
@@ -149,6 +149,7 @@ int main() {
|
|
|
|
|
|
**c++ version**: [evpp/TcpClient_test.cpp](evpp/TcpClient_test.cpp)
|
|
|
```c++
|
|
|
+#include <iostream>
|
|
|
#include "TcpClient.h"
|
|
|
using namespace hv;
|
|
|
|
|
|
@@ -163,7 +164,6 @@ int main() {
|
|
|
std::string peeraddr = channel->peeraddr();
|
|
|
if (channel->isConnected()) {
|
|
|
printf("connected to %s! connfd=%d\n", peeraddr.c_str(), channel->fd());
|
|
|
- channel->write("hello");
|
|
|
} else {
|
|
|
printf("disconnected to %s! connfd=%d\n", peeraddr.c_str(), channel->fd());
|
|
|
}
|
|
|
@@ -173,8 +173,20 @@ int main() {
|
|
|
};
|
|
|
cli.start();
|
|
|
|
|
|
- // press Enter to stop
|
|
|
- while (getchar() != '\n');
|
|
|
+ std::string str;
|
|
|
+ while (std::getline(std::cin, str)) {
|
|
|
+ if (str == "close") {
|
|
|
+ cli.closesocket();
|
|
|
+ } else if (str == "start") {
|
|
|
+ cli.start();
|
|
|
+ } else if (str == "stop") {
|
|
|
+ cli.stop();
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ if (!cli.isConnected()) break;
|
|
|
+ cli.send(str);
|
|
|
+ }
|
|
|
+ }
|
|
|
return 0;
|
|
|
}
|
|
|
```
|
|
|
@@ -304,8 +316,8 @@ using namespace hv;
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
WebSocketService ws;
|
|
|
- ws.onopen = [](const WebSocketChannelPtr& channel, const std::string& url) {
|
|
|
- printf("onopen: GET %s\n", url.c_str());
|
|
|
+ ws.onopen = [](const WebSocketChannelPtr& channel, const HttpRequestPtr& req) {
|
|
|
+ printf("onopen: GET %s\n", req->Path().c_str());
|
|
|
};
|
|
|
ws.onmessage = [](const WebSocketChannelPtr& channel, const std::string& msg) {
|
|
|
printf("onmessage: %.*s\n", (int)msg.size(), msg.data());
|