Browse Source

cmd add remote_host

ithewei 2 years ago
parent
commit
13f28ba6fd
2 changed files with 16 additions and 8 deletions
  1. 8 4
      evpp/TcpClient_test.cpp
  2. 8 4
      evpp/UdpClient_test.cpp

+ 8 - 4
evpp/TcpClient_test.cpp

@@ -19,17 +19,21 @@ using namespace hv;
 
 int main(int argc, char* argv[]) {
     if (argc < 2) {
-        printf("Usage: %s port\n", argv[0]);
+        printf("Usage: %s remote_port [remote_host]\n", argv[0]);
         return -10;
     }
-    int port = atoi(argv[1]);
+    int remote_port = atoi(argv[1]);
+    const char* remote_host = "127.0.0.1";
+    if (argc > 2) {
+        remote_host = argv[2];
+    }
 
     TcpClient cli;
-    int connfd = cli.createsocket(port);
+    int connfd = cli.createsocket(remote_port, remote_host);
     if (connfd < 0) {
         return -20;
     }
-    printf("client connect to port %d, connfd=%d ...\n", port, connfd);
+    printf("client connect to port %d, connfd=%d ...\n", remote_port, connfd);
     cli.onConnection = [&cli](const SocketChannelPtr& channel) {
         std::string peeraddr = channel->peeraddr();
         if (channel->isConnected()) {

+ 8 - 4
evpp/UdpClient_test.cpp

@@ -16,17 +16,21 @@ using namespace hv;
 
 int main(int argc, char* argv[]) {
     if (argc < 2) {
-        printf("Usage: %s port\n", argv[0]);
+        printf("Usage: %s remote_port [remote_host]\n", argv[0]);
         return -10;
     }
-    int port = atoi(argv[1]);
+    int remote_port = atoi(argv[1]);
+    const char* remote_host = "127.0.0.1";
+    if (argc > 2) {
+        remote_host = argv[2];
+    }
 
     UdpClient cli;
-    int sockfd = cli.createsocket(port);
+    int sockfd = cli.createsocket(remote_port, remote_host);
     if (sockfd < 0) {
         return -20;
     }
-    printf("client sendto port %d, sockfd=%d ...\n", port, sockfd);
+    printf("client sendto port %d, sockfd=%d ...\n", remote_port, sockfd);
     cli.onMessage = [](const SocketChannelPtr& channel, Buffer* buf) {
         printf("< %.*s\n", (int)buf->size(), (char*)buf->data());
     };