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

---
 doc/使用指南.mk |   87 +++++++++++++++++++++++++++++--------------
 1 files changed, 58 insertions(+), 29 deletions(-)

diff --git "a/doc/\344\275\277\347\224\250\346\214\207\345\215\227.mk" "b/doc/\344\275\277\347\224\250\346\214\207\345\215\227.mk"
index 2b2e126..4514d41 100644
--- "a/doc/\344\275\277\347\224\250\346\214\207\345\215\227.mk"
+++ "b/doc/\344\275\277\347\224\250\346\214\207\345\215\227.mk"
@@ -25,19 +25,21 @@
 ```
 
 ### 2.2 鍚姩BusService
-BusService锛� Pub/Sub Client 鍜� Request/Reply Client鐨勫ご鏂囦欢閮芥槸 net_mod_socket_wrapper.h锛� 涓嬮潰鍚姩key鏄�8鐨凚us鏈嶅姟.
+BusService鐨勫ご鏂囦欢鏄痓us_server_socket_wrapper.h锛� 涓嬮潰鏄惎鍔˙us鏈嶅姟鐨勪唬鐮�.
 
 ```
-
-void * server_socket = net_mod_socket_open();
-
-net_mod_socket_bind(server_socket, 8);
-
-net_mod_socket_start_bus(server_socket);
+void * server_socket = bus_server_socket_wrapper_open();
+if(bus_server_socket_wrapper_start_bus(server_socket) != 0) {
+    printf("start bus failed\n");
+    exit(1);
+}
 
 ```
 
 ###  2.3 Request/Reply 鐢ㄤ緥璇存槑
+
+Pub/Sub Client 鍜� Request/Reply Client鐨勫ご鏂囦欢閮芥槸 net_mod_socket_wrapper.h
+ 
 鐜板湪妯℃嫙涓�涓満鏅紝A鍚態鍜孋鍙戦�佷竴涓姹傦紝B鍜孋鏀跺埌璇锋眰鍚庡垎鍒繑鍥炰竴涓搷搴旂粰A 銆傚亣璁続鐨処P鏄�192.168.20.101锛孊鐨処P鏄�192.168.20.102, C鐨処P鏄�192.168.20.103, 瀹冧滑鐨刱ey閮芥槸100锛� 浠g悊server鐨勭鍙f槸5000銆�
 
 A 鐨勪唬鐮佸涓嬶細
@@ -54,7 +56,9 @@
 int node_arr_size = 2;
 
 void *client = net_mod_socket_open();
-n = net_mod_socket_sendandrecv(client, node_arr, node_arr_size, content, strlen(content), &recv_arr, &recv_arr_size);
+n = net_mod_socket_sendandrecv(client, node_arr, node_arr_size, 
+	content, strlen(content), &recv_arr, &recv_arr_size);
+    
 printf(">>> %d nodes reply\n", n);
 for(i=0; i<recv_arr_size; i++) {
     printf("host:%s, port: %d, key:%d, content: %s\n", 
@@ -91,37 +95,62 @@
 
 ### 2.3 Pub/Sub 鐢ㄤ緥璇存槑
 
-鐜板湪妯℃嫙涓�涓満鏅紝B 鍜� C璁㈤槄浜嗕富棰榥ews, A 鍙戝竷浜嗚涓婚鐩稿叧鐨勫唴瀹� 銆傚亣璁続鐨処P鏄�192.168.20.101锛孊鐨処P鏄�192.168.20.102, C鐨処P鏄�192.168.20.103, 瀹冧滑鐨刱ey閮芥槸200锛� Bus鐨刱ey鏄�8锛� 浠g悊server鐨勭鍙f槸5000.
+鐜板湪妯℃嫙涓�涓満鏅紝B 鍜� C璁㈤槄浜嗕富棰榥ews, A 鍙戝竷浜嗚涓婚鐩稿叧鐨勫唴瀹� 銆傚亣璁続鐨処P鏄�192.168.20.101锛孊鐨処P鏄�192.168.20.102, C鐨処P鏄�192.168.20.103, 瀹冧滑鐨刱ey閮芥槸200锛�  浠g悊server鐨勭鍙f槸5000.
 
 A鐨勪唬鐮佸涓嬶細
 
 ```
-int n;
-const char* topic = "news":
-const char* content = "HELLO WORLD!":
-void *client = net_mod_socket_open();
-net_mod_socket_bind(client, 200);
-net_node_t node_arr = {
-	{"192.168.20.102", 5000, 8},
-    {"192.168.20.103", 5000, 8}
-};
-int node_arr_size = 2;
+int main() {
+	int n;
+    const char* topic = "news":
+    const char* content = "HELLO WORLD!":
+    void *client = net_mod_socket_open();
+    net_mod_socket_bind(client, 200);
+    net_node_t node_arr = {
+        {"192.168.20.102", 5000},
+        {"192.168.20.103", 5000}
+    };
+    int node_arr_size = 2;
 
-void *client = net_mod_socket_open();
-net_mod_socket_bind(client, 200);
-n = net_mod_socket_pub(client, pub_node_arr, pub_node_arr_size, topic, strlen(topic)+1, content, strlen(content)+1);
-printf("pub %d nodes\n", n);
+    void *client = net_mod_socket_open();
+    net_mod_socket_bind(client, 200);
+    n = net_mod_socket_pub(client, pub_node_arr, 
+    	pub_node_arr_size, topic, strlen(topic)+1, content, strlen(content)+1);
+        
+    printf("pub %d nodes\n", n);
+}
+
 ```
 
 B 鍜� C 鐨勪唬鐮佸涓�
 ```
-const char* topic = "news":
-
-void *client = net_mod_socket_open();
-net_mod_socket_bind(client, 200);
-while (net_mod_socket_sub(client, topic, strlen(topic),  8) == 0) {
- printf("%d Sub success!\n", net_mod_socket_get_key(client));
+// 鎵撳嵃鎺ュ彈鍒扮殑璁㈤槄娑堟伅
+void *print_sub_msg(void *sockt) {
+  pthread_detach(pthread_self());
+  void *recvbuf;
+  int size;
+  int key;
+  while (net_mod_socket_recvfrom( sockt, &recvbuf, &size, &key) == 0) {
+    printf("鏀跺埌璁㈤槄娑堟伅:%s\n", recvbuf);
+    free(recvbuf);
+  }
+  
 }
+
+int main() {
+    pthread_t tid;
+    // 鍒涘缓涓�涓嚎绋嬫帴鍙楄闃呮秷鎭�
+    pthread_create(&tid, NULL, print_sub_msg, client);
+    const char* topic = "news":
+
+    void *client = net_mod_socket_open();
+    net_mod_socket_bind(client, 200);
+    // 璁㈤槄鎰熷叴瓒g殑涓婚
+    if (net_mod_socket_sub(client, topic, strlen(topic)) == 0) {
+     printf("%d Sub success!\n", net_mod_socket_get_key(client));
+    }
+}
+
 ```
 
 鏇村叿浣撶殑瀹炰緥浠g爜璇峰弬鐪媊test_net_mod_socket.c`

--
Gitblit v1.8.0