From b750d359d742349be27463a5408f352aa042fdec Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期五, 15 一月 2021 15:59:31 +0800
Subject: [PATCH] update

---
 doc/使用指南.mk |   89 +++++++++++++++++++++++++++++---------------
 1 files changed, 59 insertions(+), 30 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..b77ef8a 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"
@@ -3,7 +3,7 @@
     
 ## 1. BHomeBus鍖呭惈鐨勮鑹�
 - NetProxyService锛堢綉缁滀唬鐞嗘湇鍔★級锛� 璐熻矗璺ㄦ満鍣ㄨ浆鍙戝彂甯冩垨璇锋眰娑堟伅
-- BusService锛� 鎬荤嚎鏈嶅姟锛�: 鍙戝竷璁㈤槄鐨勮矾鐢憋紝璐熻矗璁板綍璁㈤槄鑰呯殑娑堟伅骞舵妸鍙戝竷鑰呭彂甯冪殑娑堟伅杞彂缁欐劅鍏磋叮鐨勮闃呰�呫��
+- BusService锛堟�荤嚎鏈嶅姟锛�: 鍙戝竷璁㈤槄鐨勮矾鐢憋紝璐熻矗璁板綍璁㈤槄鑰呯殑娑堟伅骞舵妸鍙戝竷鑰呭彂甯冪殑娑堟伅杞彂缁欐劅鍏磋叮鐨勮闃呰�呫��
 - Pub/Sub Client锛堝彂甯冭闃呭鎴风锛夛細 鍚態usService鍙戝竷娑堟伅鎴栬�呭湪BusService涓婅闃呮劅鍏磋叮鐨勬秷鎭�
 - Request/Reply Client 锛堣姹傚簲绛斿鎴风锛夛細鍚戝叾浠栨満鍣�/杩涚▼鍙戦�佽姹傛秷鎭垨鑰呬粠鍏朵粬鏈哄櫒/杩涚▼鎺ュ彈搴旂瓟娑堟伅
 
@@ -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