Skip to content

Commit 13f28ba

Browse files
committed
cmd add remote_host
1 parent 88ffe5f commit 13f28ba

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

evpp/TcpClient_test.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,21 @@ using namespace hv;
1919

2020
int main(int argc, char* argv[]) {
2121
if (argc < 2) {
22-
printf("Usage: %s port\n", argv[0]);
22+
printf("Usage: %s remote_port [remote_host]\n", argv[0]);
2323
return -10;
2424
}
25-
int port = atoi(argv[1]);
25+
int remote_port = atoi(argv[1]);
26+
const char* remote_host = "127.0.0.1";
27+
if (argc > 2) {
28+
remote_host = argv[2];
29+
}
2630

2731
TcpClient cli;
28-
int connfd = cli.createsocket(port);
32+
int connfd = cli.createsocket(remote_port, remote_host);
2933
if (connfd < 0) {
3034
return -20;
3135
}
32-
printf("client connect to port %d, connfd=%d ...\n", port, connfd);
36+
printf("client connect to port %d, connfd=%d ...\n", remote_port, connfd);
3337
cli.onConnection = [&cli](const SocketChannelPtr& channel) {
3438
std::string peeraddr = channel->peeraddr();
3539
if (channel->isConnected()) {

evpp/UdpClient_test.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@ using namespace hv;
1616

1717
int main(int argc, char* argv[]) {
1818
if (argc < 2) {
19-
printf("Usage: %s port\n", argv[0]);
19+
printf("Usage: %s remote_port [remote_host]\n", argv[0]);
2020
return -10;
2121
}
22-
int port = atoi(argv[1]);
22+
int remote_port = atoi(argv[1]);
23+
const char* remote_host = "127.0.0.1";
24+
if (argc > 2) {
25+
remote_host = argv[2];
26+
}
2327

2428
UdpClient cli;
25-
int sockfd = cli.createsocket(port);
29+
int sockfd = cli.createsocket(remote_port, remote_host);
2630
if (sockfd < 0) {
2731
return -20;
2832
}
29-
printf("client sendto port %d, sockfd=%d ...\n", port, sockfd);
33+
printf("client sendto port %d, sockfd=%d ...\n", remote_port, sockfd);
3034
cli.onMessage = [](const SocketChannelPtr& channel, Buffer* buf) {
3135
printf("< %.*s\n", (int)buf->size(), (char*)buf->data());
3236
};

0 commit comments

Comments
 (0)