From 2a4e4619f34a742e36693e589e0431347a72979b Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期二, 13 十月 2020 17:36:32 +0800
Subject: [PATCH] update

---
 test_net_socket/net_mod_req_rep.c |   74 ++++++++++++++++++++++++++++---------
 1 files changed, 56 insertions(+), 18 deletions(-)

diff --git a/test_net_socket/net_mod_req_rep.c b/test_net_socket/net_mod_req_rep.c
index 3287d58..df33bf0 100644
--- a/test_net_socket/net_mod_req_rep.c
+++ b/test_net_socket/net_mod_req_rep.c
@@ -11,30 +11,68 @@
 
 void client(int port ){
 	NetModSocket client;
-	char send_buf[MAXLINE];
+	char content[MAXLINE];
+	char action[512];
+  char topic[512];
 	net_mod_recv_msg_t *recv_arr;
-	int recv_arr_size, i;
+	int recv_arr_size, i, n;
+	int node_arr_size = 3;
+	//192.168.20.104
 	net_node_t node_arr[] = {
-		{"localhost", port, 11},
-		{"localhost", port, 12},
-		{"localhost", port, 13},
-		{"localhost", port, 14}
+		{"192.168.20.104", port, 11},
+		{"192.168.20.104", port, 12},
+		{"192.168.20.104", port, 13}
 	};
 
-  while (fgets(send_buf, MAXLINE, stdin) != NULL) {
-  	// 鏀跺埌娑堟伅鐨勮妭鐐瑰嵆浣挎病鏈夊搴旂殑淇℃伅锛� 涔熻鍥炲涓�涓〃绀烘棤鐨勬秷鎭�,鍚﹀垯浼氫竴鐩寸瓑寰�
-    client.sendandrecv( node_arr, 4, send_buf, strlen(send_buf), &recv_arr, &recv_arr_size);
-    for(i=0; i<recv_arr_size; i++) {
-    	printf("host:%s, port: %d, key:%d, content: %s\n", 
-    		recv_arr[i].host,
-    		recv_arr[i].port,
-    		recv_arr[i].key,
-    		recv_arr[i].content
-    	);
+	int pub_node_arr_size = 3;
+	net_node_t pub_node_arr[] = {
+		{"192.168.20.104", port, 8},
+		{"192.168.20.104", port, 8},
+		{"192.168.20.104", port, 8}
+	};
+	
+  while (true) {
+    //printf("Usage: pub <topic> [content] or sub <topic>\n");
+    printf("Can I help you? pub, send or quit\n");
+    scanf("%s",action);
+    
+    if(strcmp(action, "pub") == 0) {
+    	printf("Please input topic and content\n");
+      scanf("%s %s", topic, content);
+
+    	n = client.pub(pub_node_arr, pub_node_arr_size, topic, strlen(topic)+1, content, strlen(content)+1);
+    	printf("pub %d\n", n);
     }
-//浣跨敤瀹屽悗锛屼笉瑕佸繕璁伴噴鏀炬帀
-    NetModSocket::free_recv_msg_arr(recv_arr, recv_arr_size);
+    else if(strcmp(action, "send") == 0) {
+    	getc(stdin);
+    	printf("Please input  content\n");
+    	
+		  if (fgets(content, MAXLINE, stdin) != NULL) {
+		  	// 鏀跺埌娑堟伅鐨勮妭鐐瑰嵆浣挎病鏈夊搴旂殑淇℃伅锛� 涔熻鍥炲涓�涓〃绀烘棤鐨勬秷鎭�,鍚﹀垯浼氫竴鐩寸瓑寰�
+		    n = client.sendandrecv( node_arr, node_arr_size, content, strlen(content), &recv_arr, &recv_arr_size);
+		    for(i=0; i<recv_arr_size; i++) {
+		    	printf("host:%s, port: %d, key:%d, content: %s\n", 
+		    		recv_arr[i].host,
+		    		recv_arr[i].port,
+		    		recv_arr[i].key,
+		    		recv_arr[i].content
+		    	);
+		    }
+		//浣跨敤瀹屽悗锛屼笉瑕佸繕璁伴噴鏀炬帀
+		    NetModSocket::free_recv_msg_arr(recv_arr, recv_arr_size);
+		  }
+    }
+    else if(strcmp(action, "quit") == 0) {
+      break;
+    } else {
+      printf("error input argument\n");
+      continue;
+    }
+   
   }
+
+
+  
 }
 
 int main(int argc, char *argv[]) {

--
Gitblit v1.8.0