{"id":33896,"date":"2025-04-28T17:40:39","date_gmt":"2025-04-28T09:40:39","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/33896.html"},"modified":"2025-04-28T17:40:39","modified_gmt":"2025-04-28T09:40:39","slug":"%e6%96%bd%e7%a3%8a%e8%80%81%e5%b8%88%e5%9f%ba%e4%ba%8emuduo%e7%bd%91%e7%bb%9c%e5%ba%93%e7%9a%84%e9%9b%86%e7%be%a4%e8%81%8a%e5%a4%a9%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%b8%83","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/33896.html","title":{"rendered":"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e03)"},"content":{"rendered":"<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\u6570\u636e\u8868\u5b57\u7b26\u96c6\u95ee\u9898<\/li>\n<li>\n<ul>\n<li>\u652f\u6301\u4e2d\u6587\u548c\u82f1\u6587<\/li>\n<li>\n<ul>\n<li>**\u4e3a\u4ec0\u4e48\u4f7f\u7528 &#096;utf8mb4&#096;&#xff1f;**<\/li>\n<\/ul>\n<\/li>\n<li>\u63a8\u8350 \u67e5\u770b\u6574\u4e2a\u8868, \u518d\u5355\u72ec\u4fee\u6539<\/li>\n<\/ul>\n<\/li>\n<li>\u5ba2\u6237\u7aef\u7fa4\u7ec4\u529f\u80fd<\/li>\n<li>\n<ul>\n<li>\u521b\u5efa\u7fa4\u7ec4<\/li>\n<li>\u6dfb\u52a0\u7fa4\u7ec4<\/li>\n<li>\u7fa4\u7ec4\u804a\u5929<\/li>\n<li>\u63a5\u6536\u5728\u7ebf\u7fa4\u7ec4\u6d88\u606f<\/li>\n<li>\u63a5\u6536\u79bb\u7ebf\u7fa4\u7ec4\u6d88\u606f<\/li>\n<li>\u8865\u5145\u670d\u52a1\u5668\u4e8b\u4ef6\u5904\u7406\u5668<\/li>\n<li>\u8865\u5145\u670d\u52a1\u5668\u67e5\u8be2\u7fa4\u7ec4\u5217\u8868<\/li>\n<li>\u95ee\u9898\u89e3\u51b3<\/li>\n<li>\u6d4b\u8bd5<\/li>\n<\/ul>\n<\/li>\n<li>\u76ee\u524d\u62a5\u9519\u603b\u7ed3<\/li>\n<li>\u76ee\u524d\u4e3a\u6b62\u6700\u6076\u5fc3\u7684\u9519\u8bef<\/li>\n<li>\u5ba2\u6237\u7aef\u7528\u6237\u6ce8\u9500\u529f\u80fd<\/li>\n<li>\n<ul>\n<li>1. \u7528\u6237\u6ce8\u9500\u529f\u80fd\u7684\u8bbe\u8ba1\u4e0e\u5b9e\u73b0<\/li>\n<li>2. \u5ba2\u6237\u7aef\u72b6\u6001\u7ba1\u7406\u4e0e\u5faa\u73af\u63a7\u5236<\/li>\n<li>3. \u6570\u636e\u91cd\u590d\u52a0\u8f7d\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/li>\n<li>4. \u63a5\u6536\u7ebf\u7a0b\u7684\u5355\u4f8b\u63a7\u5236-**\u91cd\u70b9**<\/li>\n<li>\u5de7\u7528\u9759\u6001\u5c40\u90e8\u53d8\u91cf<\/li>\n<li>\u8001\u5e08\u8fd9\u8282\u8bfe\u8fdb\u884c\u4e86\u4e00\u4e2a\u5c0f\u603b\u7ed3<\/li>\n<li>5. \u67b6\u6784\u8bbe\u8ba1\u601d\u60f3<\/li>\n<li>6. \u96c6\u7fa4\u5316\u6269\u5c55\u7684\u94fa\u57ab<\/li>\n<li>\u9519\u8bef<\/li>\n<li>\u4ee3\u7801<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u6570\u636e\u8868\u5b57\u7b26\u96c6\u95ee\u9898<\/h2>\n<h3>\u652f\u6301\u4e2d\u6587\u548c\u82f1\u6587<\/h3>\n<h4>\u4e3a\u4ec0\u4e48\u4f7f\u7528 utf8mb4&#xff1f;<\/h4>\n<li>\u652f\u6301\u5b8c\u6574\u7684 Unicode \u5b57\u7b26&#xff1a;\n<ul>\n<li>utf8mb4 \u53ef\u4ee5\u5b58\u50a8\u51e0\u4e4e\u6240\u6709\u8bed\u8a00\u7684\u5b57\u7b26&#xff0c;\u652f\u6301 \u4e2d\u6587\u3001\u65e5\u6587\u3001\u97e9\u6587&#xff0c;\u4ee5\u53ca Emoji \u548c\u7b26\u53f7\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u6bd4 utf8 \u66f4\u52a0\u53ef\u9760&#xff1a;\n<ul>\n<li>utf8 \u53ea\u652f\u6301\u6700\u591a\u4e09\u4e2a\u5b57\u8282\u7684\u5b57\u7b26&#xff08;\u4e0d\u652f\u6301\u4e00\u4e9b 4 \u5b57\u8282\u5b57\u7b26&#xff0c;\u5982 Emoji&#xff09;&#xff0c;\u800c utf8mb4 \u652f\u6301\u6700\u591a\u56db\u4e2a\u5b57\u8282\u7684\u5b57\u7b26\u3002<\/li>\n<\/ul>\n<\/li>\n<p>\u67e5\u770b\u6570\u636e\u5e93 \u6240\u6709\u8868\u7684 \u5b57\u7b26\u96c6<\/p>\n<p>SELECT<br \/>\n    TABLE_NAME,<br \/>\n    TABLE_COLLATION<br \/>\nFROM<br \/>\n    information_schema.TABLES<br \/>\nWHERE<br \/>\n    TABLE_SCHEMA &#061; &#039;\u4f60\u7684\u6570\u636e\u5e93\u540d&#039;;<\/p>\n<p>\u5355\u72ec\u4fee\u6539\u67d0\u4e2a\u8868<\/p>\n<p>ALTER TABLE \u8868\u540d CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;<\/p>\n<p>\u6279\u91cf\u4fee\u6539\u5b57\u7b26\u96c6\u2013\u4fee\u6539\u67d0\u4e2a\u5b57\u7b26\u96c6\u7684\u6240\u6709\u8868<\/p>\n<p>SELECT<br \/>\n    CONCAT(&#039;ALTER TABLE &#039;, TABLE_NAME, &#039; CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;&#039;)<br \/>\nFROM<br \/>\n    information_schema.TABLES<br \/>\nWHERE<br \/>\n    TABLE_SCHEMA &#061; &#039;\u4f60\u7684\u6570\u636e\u5e93\u540d&#039;<br \/>\n    AND TABLE_COLLATION LIKE &#039;latin1%&#039;;<\/p>\n<h3>\u63a8\u8350 \u67e5\u770b\u6574\u4e2a\u8868, \u518d\u5355\u72ec\u4fee\u6539<\/h3>\n<h2>\u5ba2\u6237\u7aef\u7fa4\u7ec4\u529f\u80fd<\/h2>\n<h3>\u521b\u5efa\u7fa4\u7ec4<\/h3>\n<p>\/\/ creategroup\u51fd\u6570<br \/>\nvoid creategroup(int clientfd, string msg)<br \/>\n{<br \/>\n    int idx &#061; msg.find(&#034;:&#034;); \/\/ \u67e5\u627e\u7b2c\u4e00\u4e2a:\u7684\u4f4d\u7f6e<br \/>\n    if (idx &#061;&#061; string::npos) \/\/ \u6ca1\u6709\u627e\u5230  &#061;&#061;-1-&gt;\u4e0d\u5efa\u8bae\u7528<br \/>\n    {<br \/>\n        cout &lt;&lt; &#034;creategroup command: group name is invalid!&#034; &lt;&lt; endl;<br \/>\n        return;<br \/>\n    }<br \/>\n    string groupname &#061; msg.substr(0, idx);                        \/\/ \u622a\u53d6\u7fa4\u7ec4\u540d\u79f0<br \/>\n    string groupdesc &#061; msg.substr(idx &#043; 1, msg.size() &#8211; idx &#8211; 1); \/\/ \u622a\u53d6\u7fa4\u7ec4\u63cf\u8ff0<\/p>\n<p>    json js;<br \/>\n    js[&#034;msgid&#034;] &#061; CREATE_GROUP_MSG;   \/\/ \u521b\u5efa\u7fa4\u7ec4\u6d88\u606f<br \/>\n    js[&#034;id&#034;] &#061; g_currentUser.getId(); \/\/ \u5f53\u524d\u767b\u5f55\u7528\u6237id<br \/>\n    js[&#034;groupname&#034;] &#061; groupname;      \/\/ \u7fa4\u7ec4\u540d\u79f0<br \/>\n    js[&#034;groupdesc&#034;] &#061; groupdesc;      \/\/ \u7fa4\u7ec4\u63cf\u8ff0<\/p>\n<p>    string request &#061; js.dump();                                                \/\/ json\u8f6c\u5b57\u7b26\u4e32  \u5e8f\u5217\u5316<br \/>\n    int len &#061; send(clientfd, request.c_str(), strlen(request.c_str()) &#043; 1, 0); \/\/ \u53d1\u9001\u6570\u636e<br \/>\n    if (len &lt; 0)<br \/>\n    {<br \/>\n        cerr &lt;&lt; &#034;send creategroup msg error: &#034; &lt;&lt; request &lt;&lt; endl;<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u6dfb\u52a0\u7fa4\u7ec4<\/h3>\n<p>\/\/ addgroup\u51fd\u6570<br \/>\nvoid addgroup(int clientfd, string msg)<br \/>\n{<br \/>\n    int groupid &#061; atoi(msg.c_str()); \/\/ \u8f6c\u6210\u6574\u578b<\/p>\n<p>    json js;<br \/>\n    js[&#034;msgid&#034;] &#061; ADD_GROUP_MSG;      \/\/ \u6dfb\u52a0\u7fa4\u7ec4\u6d88\u606f<br \/>\n    js[&#034;id&#034;] &#061; g_currentUser.getId(); \/\/ \u5f53\u524d\u767b\u5f55\u7528\u6237id<br \/>\n    js[&#034;groupid&#034;] &#061; groupid;          \/\/ \u7fa4\u7ec4id<\/p>\n<p>    string request &#061; js.dump();                                                \/\/ json\u8f6c\u5b57\u7b26\u4e32  \u5e8f\u5217\u5316<br \/>\n    int len &#061; send(clientfd, request.c_str(), strlen(request.c_str()) &#043; 1, 0); \/\/ \u53d1\u9001\u6570\u636e<br \/>\n    if (len &lt; 0)<br \/>\n    {<br \/>\n        cerr &lt;&lt; &#034;send addgroup msg error: &#034; &lt;&lt; request &lt;&lt; endl;<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u7fa4\u7ec4\u804a\u5929<\/h3>\n<p>\/\/ groupchat\u51fd\u6570<br \/>\nvoid groupchat(int clientfd, string msg)<br \/>\n{<br \/>\n    int idx &#061; msg.find(&#034;:&#034;); \/\/ \u67e5\u627e\u7b2c\u4e00\u4e2a:\u7684\u4f4d\u7f6e<br \/>\n    if (idx &#061;&#061; string::npos) \/\/ \u6ca1\u6709\u627e\u5230  &#061;&#061;-1-&gt;\u4e0d\u5efa\u8bae\u7528<br \/>\n    {<br \/>\n        cout &lt;&lt; &#034;groupchat command: group id is invalid!&#034; &lt;&lt; endl;<br \/>\n        return;<br \/>\n    }<br \/>\n    int groupid &#061; atoi(msg.substr(0, idx).c_str());             \/\/ \u622a\u53d6\u7fa4\u7ec4id<br \/>\n    string message &#061; msg.substr(idx &#043; 1, msg.size() &#8211; idx &#8211; 1); \/\/ \u622a\u53d6\u804a\u5929\u4fe1\u606f<\/p>\n<p>    json js;<br \/>\n    js[&#034;msgid&#034;] &#061; GROUP_CHAT_MSG;         \/\/ \u7fa4\u7ec4\u804a\u5929\u6d88\u606f<br \/>\n    js[&#034;id&#034;] &#061; g_currentUser.getId();     \/\/ \u5f53\u524d\u767b\u5f55\u7528\u6237id<br \/>\n    js[&#034;name&#034;] &#061; g_currentUser.getName(); \/\/ \u5f53\u524d\u767b\u5f55\u7528\u6237\u59d3\u540d<br \/>\n    js[&#034;groupid&#034;] &#061; groupid;              \/\/ \u7fa4\u7ec4id  &#8212; \u5b57\u6bb5\u8981\u5bf9\u5e94\u670d\u52a1\u5668\u90a3\u8fb9\u7684<br \/>\n    js[&#034;msg&#034;] &#061; message;                  \/\/ \u804a\u5929\u4fe1\u606f<br \/>\n    js[&#034;time&#034;] &#061; getCurrentTime();        \/\/ \u65f6\u95f4<\/p>\n<p>    \/\/ \u53d1\u9001\u804a\u5929\u8bf7\u6c42<br \/>\n    string request &#061; js.dump();                                                \/\/ json\u8f6c\u5b57\u7b26\u4e32  \u5e8f\u5217\u5316<br \/>\n    int len &#061; send(clientfd, request.c_str(), strlen(request.c_str()) &#043; 1, 0); \/\/ \u53d1\u9001\u6570\u636e<br \/>\n    if (len &lt; 0)<br \/>\n    {<br \/>\n        cerr &lt;&lt; &#034;send groupchat msg error: &#034; &lt;&lt; request &lt;&lt; endl;<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u63a5\u6536\u5728\u7ebf\u7fa4\u7ec4\u6d88\u606f<\/h3>\n<p>\u533a\u5206\u7fa4\u7ec4\u6d88\u606f\u548c\u4e2a\u4eba\u6d88\u606f<\/p>\n<p>readTaskHandler\u51fd\u6570<\/p>\n<p>\/\/ \u89e3\u6790json\u6570\u636e<br \/>\njson response &#061; json::parse(buffer);   \/\/ \u53cd\u5e8f\u5217\u5316 \u5b57\u7b26\u4e32\u8f6cjson<br \/>\nif (response[&#034;msgid&#034;] &#061;&#061; ONE_CHAT_MSG) \/\/ \u4e00\u5bf9\u4e00\u804a\u5929\u6d88\u606f<br \/>\n{<br \/>\n    cout &lt;&lt; response[&#034;time&#034;].get&lt;string&gt;() &lt;&lt; &#034;[&#034; &lt;&lt; response[&#034;id&#034;] &lt;&lt; &#034;] &#034; &lt;&lt; response[&#034;name&#034;].get&lt;string&gt;() &lt;&lt; &#034; said: &#034; &lt;&lt; response[&#034;msg&#034;].get&lt;string&gt;() &lt;&lt; endl;<br \/>\n    continue;<br \/>\n}<\/p>\n<p>if (response[&#034;msgid&#034;] &#061;&#061; GROUP_CHAT_MSG) \/\/ \u7fa4\u7ec4\u804a\u5929\u6d88\u606f<br \/>\n{<br \/>\n    cout &lt;&lt; &#034;\u7fa4\u6d88\u606f&#8211;&gt;[&#034; &lt;&lt; response[&#034;groupid&#034;] &lt;&lt; &#034;] &#034; &lt;&lt; response[&#034;time&#034;].get&lt;string&gt;() &lt;&lt; &#034;[&#034; &lt;&lt; response[&#034;id&#034;] &lt;&lt; &#034;] &#034; &lt;&lt; response[&#034;name&#034;].get&lt;string&gt;() &lt;&lt; &#034; said: &#034; &lt;&lt; response[&#034;msg&#034;].get&lt;string&gt;() &lt;&lt; endl;<br \/>\n}<\/p>\n<h3>\u63a5\u6536\u79bb\u7ebf\u7fa4\u7ec4\u6d88\u606f<\/h3>\n<p>\u540c\u6837\u8fdb\u884c\u533a\u5206<\/p>\n<p>main<\/p>\n<p>\/\/ \u5904\u7406\u79bb\u7ebf\u6d88\u606f<br \/>\nif (response.contains(&#034;offlinemsg&#034;)) \/\/ \u5224\u65ad\u662f\u5426\u5305\u542b\u5b57\u6bb5, \u8ddf\u597d\u70b9,  \u800c\u4e0d\u662f\u770b \u662f\u4e0d\u662f\u7a7a<br \/>\n{<br \/>\n    vector&lt;string&gt; offlinemsg &#061; response[&#034;offlinemsg&#034;]; \/\/ \u7c7b\u578b\u662fvector&lt;string&gt;, \u4e0d\u662fvector&lt;User&gt;,  \u6839\u636e\u670d\u52a1\u5668\u4e1a\u52a1,\u5b58\u7684\u662fjs.dump() \u5b57\u7b26\u4e32<br \/>\n    for (auto &amp;msg : offlinemsg)<br \/>\n    {<br \/>\n        json js &#061; json::parse(msg); \/\/ \u53cd\u5e8f\u5217\u5316<br \/>\n        \/\/ \u65f6\u95f4&#043;fromid&#043;fromname&#043;msg&#8212;&#8211;\u8be6\u770b\u7b14\u8bb0 \u4e00\u5bf9\u4e00\u804a\u5929\u53d1\u9001\u7684\u683c\u5f0f<\/p>\n<p>        \/\/ \u5206\u4e00\u4e0b \u4e2a\u4eba\u79bb\u7ebf\u548c\u7fa4\u7ec4\u79bb\u7ebf<br \/>\n        if (js[&#034;msgid&#034;] &#061;&#061; ONE_CHAT_MSG)<br \/>\n        {<br \/>\n            cout &lt;&lt; js[&#034;time&#034;].get&lt;string&gt;() &lt;&lt; &#034;[&#034; &lt;&lt; js[&#034;id&#034;].get&lt;int&gt;() &lt;&lt; &#034;] &#034; &lt;&lt; js[&#034;name&#034;].get&lt;string&gt;() &lt;&lt; &#034; said: &#034; &lt;&lt; js[&#034;msg&#034;].get&lt;string&gt;() &lt;&lt; endl;<br \/>\n        }<br \/>\n        if (js[&#034;msgid&#034;] &#061;&#061; GROUP_CHAT_MSG) \/\/ \u7fa4\u7ec4\u804a\u5929\u6d88\u606f<br \/>\n        {<br \/>\n            cout &lt;&lt; &#034;\u7fa4\u6d88\u606f&#8211;&gt;[&#034; &lt;&lt; js[&#034;groupid&#034;] &lt;&lt; &#034;] &#034; &lt;&lt; js[&#034;time&#034;].get&lt;string&gt;() &lt;&lt; &#034;[&#034; &lt;&lt; js[&#034;id&#034;] &lt;&lt; &#034;] &#034; &lt;&lt; js[&#034;name&#034;].get&lt;string&gt;() &lt;&lt; &#034; said: &#034; &lt;&lt; js[&#034;msg&#034;].get&lt;string&gt;() &lt;&lt; endl;<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u8865\u5145\u670d\u52a1\u5668\u4e8b\u4ef6\u5904\u7406\u5668<\/h3>\n<p>\u670d\u52a1\u5668\u4e1a\u52a1\u2014&gt; \u6ca1\u6709\u52a0 \u7fa4\u7ec4\u76f8\u5173\u7684 \u4e8b\u4ef6\u5904\u7406\u5668<\/p>\n<h3>\u8865\u5145\u670d\u52a1\u5668\u67e5\u8be2\u7fa4\u7ec4\u5217\u8868<\/h3>\n<p>\u767b\u5f55\u6210\u529f\u2013\u67e5\u8be2\u7fa4\u7ec4\u5217\u8868<\/p>\n<p>\/\/ \u67e5\u8be2\u7fa4\u7ec4\u5217\u8868<br \/>\nvector&lt;Group&gt; groupVec &#061; _groupModel.queryGroups(id);<br \/>\nif (!groupVec.empty())<br \/>\n{<br \/>\n    vector&lt;string&gt; vec;<br \/>\n    for (auto &amp;groupl : groupVec)<br \/>\n    {<br \/>\n        json js ;<br \/>\n        js[&#034;id&#034;] &#061; groupl.getId();<br \/>\n        js[&#034;groupname&#034;] &#061; groupl.getName();<br \/>\n        js[&#034;groupdesc&#034;] &#061; groupl.getDesc();<\/p>\n<p>        vector&lt;string&gt; usersvec;<br \/>\n        for (auto &amp;user : groupl.getUsers())<br \/>\n        {<br \/>\n            json js;<br \/>\n            js[&#034;id&#034;]&#061;user.getId();<br \/>\n            js[&#034;name&#034;]&#061;user.getName();<br \/>\n            js[&#034;state&#034;]&#061;user.getState();<br \/>\n            js[&#034;role&#034;] &#061; user.getRole();<br \/>\n            usersvec.push_back(js.dump());<br \/>\n        }<br \/>\n        js[&#034;users&#034;] &#061; usersvec;<br \/>\n        vec.push_back(js.dump());<br \/>\n    }<br \/>\n    response[&#034;groups&#034;] &#061; vec; \/\/ \u7fa4\u7ec4\u5217\u8868<br \/>\n}<\/p>\n<h3>\u95ee\u9898\u89e3\u51b3<\/h3>\n<p>\u670d\u52a1\u5668\u90e8\u5206 groupmodel.cpp \u6709\u4e00\u4e9b\u903b\u8f91\u95ee\u9898, \u5bfc\u81f4\u8bfb\u4e0d\u5230\u7528\u6237, \u63d0\u524d\u8fd4\u56de\u4e86, \u5df2\u8fdb\u884c\u4fee\u6539<\/p>\n<h3>\u6d4b\u8bd5<\/h3>\n<p>\u81ea\u884c\u6d4b\u8bd5\u2014 \u81f3\u6b64,\u529f\u80fd\u90fd\u6b63\u5e38<\/p>\n<h2>\u76ee\u524d\u62a5\u9519\u603b\u7ed3<\/h2>\n<p>\u76ee\u524d\u4e86\u89e3\u7684:<\/p>\n<p>\u6570\u636e\u5e93\u4e0d\u652f\u6301 \u4e2d\u6587&#8212;&#8211;\u82f1\u6587\u6b63\u5e38<\/p>\n<p>\u6570\u636e\u5e93\u672c\u8eab\u95ee\u9898&#8212;-\u628a\u8bed\u53e5 \u5148\u5728mysql\u547d\u4ee4\u884c\u8bd5\u4e00\u4e0b, \u770b\u60c5\u51b5\u5904\u7406<\/p>\n<p>json\u5728gdb\u4e0d\u80fd\u76f4\u63a5\u770b&#8212;-\u5728\u4ee3\u7801\u4e0a\u6dfb\u52a0 \u4e34\u65f6\u91cf \u5b58\u50a8 js.dump(), \u8fdb\u884c\u67e5\u770b<\/p>\n<p>\u7531\u4e8e\u5ba2\u6237\u7aef \u548c \u670d\u52a1\u5668 \u548c mysql\u5206\u79bb, \u6240\u4ee5 \u6709\u65f6\u5019 \u53ef\u4ee5\u5206\u6b65\u6d4b\u8bd5, \u770bmysql \u6709\u6ca1\u6709, \u518d\u53bb\u6392\u9664\u95ee\u9898<\/p>\n<h2>\u76ee\u524d\u4e3a\u6b62\u6700\u6076\u5fc3\u7684\u9519\u8bef<\/h2>\n<p>terminate called after throwing an instance of &#039;nlohmann::json_abi_v3_12_0::detail::type_error&#039;<br \/>\nwhat():  [json.exception.type_error.302] type must be string, but is null<br \/>\nAborted (core dumped)<\/p>\n<p>\u8fd9\u4e2a\u9519\u8bef, \u57fa\u672c\u5c31\u662f json \u53d8\u91cf\u540d\u5199\u9519\u4e86<\/p>\n<p> type must be string, but is null&#xff1a; \u4f60\u8bd5\u56fe\u50cf\u5b57\u7b26\u4e32\u4e00\u6837\u4f7f\u7528\u4e00\u4e2a\u5b57\u6bb5&#xff08;\u5982 j[&#034;name&#034;].get&lt;std::string&gt;()&#xff09;&#xff0c;\u4f46 j[&#034;name&#034;] \u5b9e\u9645\u662f null&#xff0c;\u65e0\u6cd5\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u4e0b\u9762\u8fd9\u6bb5, cout\u91cc\u9762\u662f js. \u4e0d\u662fresponse.<\/p>\n<p>\/\/ \u5904\u7406\u79bb\u7ebf\u6d88\u606f<\/p>\n<p>\/\/ \u5206\u4e00\u4e0b \u4e2a\u4eba\u79bb\u7ebf\u548c\u7fa4\u7ec4\u79bb\u7ebf<br \/>\nif (js[&#034;msgid&#034;] &#061;&#061; ONE_CHAT_MSG)<br \/>\n{<br \/>\n    cout &lt;&lt; js[&#034;time&#034;].get&lt;string&gt;() &lt;&lt; &#034;[&#034; &lt;&lt; js[&#034;id&#034;].get&lt;int&gt;() &lt;&lt; &#034;] &#034; &lt;&lt; js[&#034;name&#034;].get&lt;string&gt;() &lt;&lt; &#034; said: &#034; &lt;&lt; js[&#034;msg&#034;].get&lt;string&gt;() &lt;&lt; endl;<br \/>\n}<br \/>\nif (js[&#034;msgid&#034;] &#061;&#061; GROUP_CHAT_MSG) \/\/ \u7fa4\u7ec4\u804a\u5929\u6d88\u606f<br \/>\n{<br \/>\n    cout &lt;&lt; &#034;\u7fa4\u6d88\u606f&#8211;&gt;[&#034; &lt;&lt; js[&#034;groupid&#034;] &lt;&lt; &#034;] &#034; &lt;&lt; js[&#034;time&#034;].get&lt;string&gt;() &lt;&lt; &#034;[&#034; &lt;&lt; js[&#034;id&#034;] &lt;&lt; &#034;] &#034; &lt;&lt; js[&#034;name&#034;].get&lt;string&gt;() &lt;&lt; &#034; said: &#034; &lt;&lt; js[&#034;msg&#034;].get&lt;string&gt;() &lt;&lt; endl;<br \/>\n}<\/p>\n<h2>\u5ba2\u6237\u7aef\u7528\u6237\u6ce8\u9500\u529f\u80fd<\/h2>\n<p>\u7528\u6237\u767b\u51fa:<\/p>\n<p>1. \u7ed3\u675fmainMenu<\/p>\n<p>2. \u7ed3\u675f\u5bf9\u5e94\u7684 \u63a5\u53d7\u7ebf\u7a0b<\/p>\n<h3>1. \u7528\u6237\u6ce8\u9500\u529f\u80fd\u7684\u8bbe\u8ba1\u4e0e\u5b9e\u73b0<\/h3>\n<p>\u533a\u5206\u4e86 quit\u2013&gt;\u6b63\u5e38\u6ce8\u9500 \u548c \u5ba2\u6237\u7aef\u5f02\u5e38\u2013&gt;ctrl&#043;c<\/p>\n<ul>\n<li>\u6b63\u5e38\u6ce8\u9500 vs. \u5f02\u5e38\u9000\u51fa&#xff1a;\n<ul>\n<li>\u6b63\u5e38\u6ce8\u9500&#xff1a;\u5ba2\u6237\u7aef\u4e3b\u52a8\u53d1\u9001 LOGOUT \u6d88\u606f&#xff0c;\u670d\u52a1\u7aef\u6536\u5230\u540e&#xff1a;\n<ul>\n<li>\u4ece connectionMap \u79fb\u9664\u8be5\u7528\u6237\u7684\u8fde\u63a5&#xff08;\u9700\u52a0\u9501\u4fdd\u8bc1\u7ebf\u7a0b\u5b89\u5168&#xff09;\u3002<\/li>\n<li>\u66f4\u65b0\u6570\u636e\u5e93&#xff0c;\u5c06\u8be5\u7528\u6237\u72b6\u6001\u8bbe\u4e3a offline\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5f02\u5e38\u9000\u51fa&#xff08;\u5982\u5ba2\u6237\u7aef\u5f3a\u5236\u5173\u95ed&#xff09;&#xff1a;\n<ul>\n<li>\u670d\u52a1\u7aef\u68c0\u6d4b\u5230\u8fde\u63a5\u65ad\u5f00&#xff0c;\u89e6\u53d1 closeException \u5904\u7406\u3002<\/li>\n<li>\u7531\u4e8e\u65e0\u6cd5\u76f4\u63a5\u83b7\u53d6\u7528\u6237ID&#xff0c;\u9700\u904d\u5386 connectionMap \u6bd4\u5bf9\u8fde\u63a5\u6765\u5220\u9664\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u5173\u952e\u70b9&#xff1a;\n<ul>\n<li>\u6b63\u5e38\u6ce8\u9500\u6bd4\u5f02\u5e38\u9000\u51fa\u66f4\u9ad8\u6548&#xff0c;\u56e0\u4e3a\u80fd\u76f4\u63a5\u901a\u8fc7 userID \u5b9a\u4f4d\u7528\u6237\u8fde\u63a5\u3002<\/li>\n<li>\u670d\u52a1\u7aef\u9700\u8981\u4fdd\u8bc1\u5bf9\u5171\u4eab\u8d44\u6e90&#xff08;\u5982 connectionMap&#xff09;\u7684\u7ebf\u7a0b\u5b89\u5168\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>2. \u5ba2\u6237\u7aef\u72b6\u6001\u7ba1\u7406\u4e0e\u5faa\u73af\u63a7\u5236<\/h3>\n<p>\u6211\u4eec\u5e0c\u671b, \u5728\u6b63\u5e38\u9000\u51fa\u540e, \u4f1a\u56de\u5230\u4e3b\u83dc\u5355\u9875\u9762!<\/p>\n<p>\u4e4b\u524d\u7684\u4ee3\u7801, \u5728\u767b\u5f55\u540e\u4f1a\u8fdb\u5165 \u83dc\u5355, \u8fdb\u5165\u6b7b\u5faa\u73af, \u53ef\u4ee5\u4e00\u76f4 \u53d1\u9001\u6d88\u606f<\/p>\n<ul>\n<li>\u5168\u5c40\u53d8\u91cf\u63a7\u5236\u9875\u9762\u8df3\u8f6c&#xff1a;\n<ul>\n<li>\u5f15\u5165 isMainMenuRunning&#xff08;\u5e03\u5c14\u503c&#xff09;\u63a7\u5236\u4e3b\u83dc\u5355\u5faa\u73af&#xff1a;\n<ul>\n<li>\u767b\u5f55\u6210\u529f \u2192 true&#xff08;\u8fdb\u5165\u4e3b\u83dc\u5355\u5faa\u73af&#xff09;\u3002<\/li>\n<li>\u6ce8\u9500 \u2192 false&#xff08;\u9000\u51fa\u5faa\u73af&#xff0c;\u8fd4\u56de\u767b\u5f55\u9875\u9762&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u907f\u514d\u56e0\u5faa\u73af\u963b\u585e\u5bfc\u81f4\u65e0\u6cd5\u8fd4\u56de\u767b\u5f55\u754c\u9762\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5173\u952e\u70b9&#xff1a;\n<ul>\n<li>\u901a\u8fc7\u72b6\u6001\u53d8\u91cf\u800c\u975e\u6b7b\u5faa\u73af\u63a7\u5236\u6d41\u7a0b&#xff0c;\u4f7f\u4ee3\u7801\u66f4\u6e05\u6670\u3001\u53ef\u7ef4\u62a4\u3002<\/li>\n<li>\u6ce8\u9500\u540e\u9700\u91cd\u7f6e\u7528\u6237\u6570\u636e&#xff08;\u5982\u597d\u53cb\u5217\u8868\u3001\u7fa4\u7ec4\u5217\u8868&#xff09;&#xff0c;\u9632\u6b62\u91cd\u590d\u52a0\u8f7d\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>3. \u6570\u636e\u91cd\u590d\u52a0\u8f7d\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/h3>\n<ul>\n<li>\u95ee\u9898&#xff1a;\n<ul>\n<li>\u7528\u6237\u6ce8\u9500\u540e\u91cd\u65b0\u767b\u5f55\u65f6&#xff0c;\u672a\u6e05\u7a7a\u65e7\u6570\u636e&#xff0c;\u5bfc\u81f4\u597d\u53cb\/\u7fa4\u7ec4\u5217\u8868\u91cd\u590d\u7d2f\u79ef\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u89e3\u51b3\u65b9\u6848&#xff1a;\n<ul>\n<li>\u6bcf\u6b21\u767b\u5f55\u65f6\u5148\u6e05\u7a7a\u5bb9\u5668&#xff08;\u5982 friendList.clear()&#xff09;&#xff0c;\u518d\u52a0\u8f7d\u65b0\u6570\u636e\u3002<\/li>\n<li>\u786e\u4fdd\u6570\u636e\u552f\u4e00\u6027&#xff0c;\u907f\u514d\u91cd\u590d\u5b58\u50a8\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>4. \u63a5\u6536\u7ebf\u7a0b\u7684\u5355\u4f8b\u63a7\u5236-\u91cd\u70b9<\/h3>\n<ul>\n<li>\u95ee\u9898&#xff1a;\n<ul>\n<li>\u591a\u6b21\u767b\u5f55\u4f1a\u91cd\u590d\u542f\u52a8\u63a5\u6536\u7ebf\u7a0b&#xff0c;\u5bfc\u81f4\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u76d1\u542c\u6d88\u606f&#xff0c;\u5f15\u53d1\u6df7\u4e71\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u89e3\u51b3\u65b9\u6848&#xff1a;\n<ul>\n<li>\u4f7f\u7528\u9759\u6001\u53d8\u91cf\u786e\u4fdd\u7ebf\u7a0b\u53ea\u542f\u52a8\u4e00\u6b21&#xff1a;\n<ul>\n<li>\u9996\u6b21\u767b\u5f55\u65f6\u542f\u52a8\u7ebf\u7a0b&#xff0c;\u540e\u7eed\u767b\u5f55\u76f4\u63a5\u590d\u7528\u3002<\/li>\n<li>\u907f\u514d\u8d44\u6e90\u6d6a\u8d39\u548c\u7ebf\u7a0b\u7ade\u4e89\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>\u5de7\u7528\u9759\u6001\u5c40\u90e8\u53d8\u91cf<\/h3>\n<p>\u9759\u6001\u5c40\u90e8\u53d8\u91cf&#xff08;static \u5c40\u90e8\u53d8\u91cf&#xff09;\u662f C\/C&#043;&#043; \u4e2d\u7684\u4e00\u79cd\u5c40\u90e8\u53d8\u91cf&#xff0c;\u5176\u7279\u70b9\u662f&#xff1a;<\/p>\n<li>\u4f5c\u7528\u57df&#xff1a;\u4e0e\u666e\u901a\u7684\u5c40\u90e8\u53d8\u91cf\u4e00\u6837&#xff0c;\u9759\u6001\u5c40\u90e8\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u4ec5\u9650\u4e8e\u51fd\u6570\u5185\u90e8\u3002\u5b83\u53ea\u80fd\u5728\u58f0\u660e\u5b83\u7684\u51fd\u6570\u5185\u4f7f\u7528&#xff0c;\u5916\u90e8\u65e0\u6cd5\u8bbf\u95ee\u3002<\/li>\n<li>\u751f\u547d\u5468\u671f&#xff1a;\u4e0e\u666e\u901a\u7684\u5c40\u90e8\u53d8\u91cf\u4e0d\u540c&#xff0c;\u9759\u6001\u5c40\u90e8\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u662f\u6574\u4e2a\u7a0b\u5e8f\u8fd0\u884c\u671f\u95f4\u3002\u5b83\u5728\u7a0b\u5e8f\u5f00\u59cb\u65f6\u5c31\u88ab\u5206\u914d\u5185\u5b58&#xff0c;\u5e76\u5728\u7a0b\u5e8f\u7ed3\u675f\u65f6\u9500\u6bc1&#xff0c;\u800c\u666e\u901a\u5c40\u90e8\u53d8\u91cf\u5219\u662f\u5728\u51fd\u6570\u8c03\u7528\u65f6\u521b\u5efa&#xff0c;\u5728\u51fd\u6570\u8c03\u7528\u7ed3\u675f\u65f6\u9500\u6bc1\u3002<\/li>\n<li>\u521d\u59cb\u5316&#xff1a;\u9759\u6001\u5c40\u90e8\u53d8\u91cf\u53ea\u4f1a\u5728\u7b2c\u4e00\u6b21\u8fdb\u5165\u8be5\u51fd\u6570\u65f6\u8fdb\u884c\u521d\u59cb\u5316&#xff0c;\u4e4b\u540e\u4e0d\u4f1a\u518d\u6b21\u521d\u59cb\u5316\u3002\u5982\u679c\u6ca1\u6709\u663e\u5f0f\u521d\u59cb\u5316&#xff0c;\u9759\u6001\u5c40\u90e8\u53d8\u91cf\u4f1a\u88ab\u9ed8\u8ba4\u521d\u59cb\u5316\u4e3a\u96f6&#xff08;\u5bf9\u4e8e\u57fa\u672c\u6570\u636e\u7c7b\u578b&#xff09;\u3002<\/li>\n<p>#include &lt;iostream&gt;<\/p>\n<p>void counterFunction() {<br \/>\n    static int counter &#061; 0; \/\/ \u9759\u6001\u5c40\u90e8\u53d8\u91cf<br \/>\n    counter&#043;&#043;;<br \/>\n    std::cout &lt;&lt; &#034;Counter: &#034; &lt;&lt; counter &lt;&lt; std::endl;<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    counterFunction(); \/\/ \u8f93\u51fa Counter: 1<br \/>\n    counterFunction(); \/\/ \u8f93\u51fa Counter: 2<br \/>\n    counterFunction(); \/\/ \u8f93\u51fa Counter: 3<br \/>\n    return 0;<br \/>\n}<\/p>\n<hr \/>\n<h3>\u8001\u5e08\u8fd9\u8282\u8bfe\u8fdb\u884c\u4e86\u4e00\u4e2a\u5c0f\u603b\u7ed3<\/h3>\n<h3>5. \u67b6\u6784\u8bbe\u8ba1\u601d\u60f3<\/h3>\n<ul>\n<li>\u5206\u5c42\u89e3\u8026&#xff1a;\n<ul>\n<li>\u7f51\u7edc\u5c42&#xff1a;\u4ec5\u8d1f\u8d23\u6570\u636e\u4f20\u8f93&#xff08;\u5982\u6536\u53d1JSON\u6d88\u606f&#xff09;\u3002<\/li>\n<li>\u4e1a\u52a1\u5c42&#xff1a;\u5904\u7406\u5177\u4f53\u903b\u8f91&#xff08;\u5982\u6ce8\u9500\u3001\u66f4\u65b0\u72b6\u6001&#xff09;&#xff0c;\u4e0d\u76f4\u63a5\u64cd\u4f5c\u6570\u636e\u5e93\u3002<\/li>\n<li>\u6570\u636e\u5c42&#xff1a;\u901a\u8fc7ORM&#xff08;\u5982User\u3001Group\u7c7b&#xff09;\u5c01\u88c5\u6570\u636e\u5e93\u64cd\u4f5c&#xff0c;\u4e1a\u52a1\u5c42\u65e0\u9700\u5173\u5fc3SQL\u7ec6\u8282\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5173\u952e\u4f18\u52bf&#xff1a;\n<ul>\n<li>\u4ee3\u7801\u53ef\u7ef4\u62a4\u6027\u9ad8&#xff0c;\u5404\u5c42\u804c\u8d23\u6e05\u6670\u3002<\/li>\n<li>\u6269\u5c55\u6027\u5f3a&#xff08;\u5982\u672a\u6765\u652f\u6301\u96c6\u7fa4\u5316&#xff0c;\u53ea\u9700\u4fee\u6539\u670d\u52a1\u7aef&#xff0c;\u5ba2\u6237\u7aef\u65e0\u611f\u77e5&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>6. \u96c6\u7fa4\u5316\u6269\u5c55\u7684\u94fa\u57ab<\/h3>\n<ul>\n<li>\u5ba2\u6237\u7aef\u65e0\u611f\u77e5&#xff1a;\n<ul>\n<li>\u65e0\u8bba\u670d\u52a1\u7aef\u662f\u5355\u673a\u8fd8\u662f\u96c6\u7fa4&#xff0c;\u5ba2\u6237\u7aef\u53ea\u9700\u53d1\u9001\u8bf7\u6c42&#xff0c;\u4e0d\u5173\u5fc3\u540e\u7aef\u5982\u4f55\u8d1f\u8f7d\u5747\u8861\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u670d\u52a1\u7aef\u96c6\u7fa4\u5316&#xff1a;\n<ul>\n<li>\u540e\u7eed\u53ef\u901a\u8fc7Nginx\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861&#xff0c;\u6c34\u5e73\u6269\u5c55\u670d\u52a1\u5668\u6027\u80fd\u3002\u5728\u5f88\u77ed\u7684\u65f6\u95f4\u5185 \u63d0\u5347\u670d\u52a1\u5668\u5e76\u53d1\u80fd\u529b<\/li>\n<li>\u9700\u89e3\u51b3\u5171\u4eab\u72b6\u6001\u95ee\u9898&#xff08;\u5982\u7528\u6237\u8fde\u63a5\u4fe1\u606f\u9700\u96c6\u4e2d\u7ba1\u7406&#xff0c;\u5982\u7528Redis&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>\u9519\u8bef<\/h3>\n<li>\n<p>main \u7684 for\u5faa\u73af \u6700\u540e \u4e0d\u8981return, \u4e0d\u7136 \u6ce8\u9500\u540e, \u4e3b\u7ebf\u7a0b\u5c31\u7ed3\u675f\u4e86<\/p>\n<\/li>\n<li>\n<p>\u8001\u5e08\u7684 \u8bfe\u4e2d, \u51fa\u73b0\u6b63\u5e38\u6ce8\u9500\u540e, \u518d\u6b21\u767b\u5f55, \u4f1a\u6253\u5370\u4e24\u8fb9\u4fe1\u606f, \u662f\u56e0\u4e3a \u90a3\u51e0\u4e2a\u53d8\u91cf\u662f \u5168\u5c40\u7684, \u6bcf\u6b21\u91cd\u65b0\u767b\u5f55\u540e\u53d8\u91cf\u6ca1\u6709\u6e05\u7a7a, \u4e4b\u524d\u7684\u4fe1\u606f\u8fd8\u5728<\/p>\n<p> g_currentUserGroupsList.clear();<br \/>\n\/\/ vector.clear()\u6e05\u7a7a\u4e00\u4e0b\n <\/li>\n<h3>\u4ee3\u7801<\/h3>\n<p>include\/public.hpp<\/p>\n<p>LOGINOUT_MSG, \/\/ \u767b\u5f55\u6210\u529f<\/p>\n<p>include\/server\/chatservice.hpp<\/p>\n<p>\/\/ \u5904\u7406\u6ce8\u9500\u4e1a\u52a1<br \/>\n    void loginout(const TcpConnectionPtr &amp;conn, json &amp;js, Timestamp time);<\/p>\n<p>src\/server\/chatservice.cpp<\/p>\n<p>_msghandlermap.insert({LOGINOUT_MSG, std::bind(&amp;ChatService::loginout, this, _1, _2, _3)});<\/p>\n<p>\/\/ \u5904\u7406\u6ce8\u9500\u4e1a\u52a1<br \/>\nvoid ChatService::loginout(const TcpConnectionPtr &amp;conn, json &amp;js, Timestamp time)<br \/>\n{<br \/>\n    int userid &#061; js[&#034;id&#034;].get&lt;int&gt;();<br \/>\n    {<br \/>\n        lock_guard&lt;mutex&gt; lock(_connMutex);<br \/>\n        auto it &#061; _userConnMap.find(userid);<br \/>\n        if(it !&#061; _userConnMap.end())<br \/>\n        {<br \/>\n            _userConnMap.erase(it);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u66f4\u65b0\u7528\u6237\u72b6\u6001<br \/>\n    User user(userid, &#034;&#034;,&#034;&#034;, &#034;offline&#034;);<br \/>\n    \/\/ user.setId(userid);<br \/>\n    \/\/ user.setState(&#034;offline&#034;);<br \/>\n    _usermodel.updateState(user); \/\/ \u4ec5\u9700\u8981id\u548c\u72b6\u6001, \u5269\u4e0b\u7684\u5177\u4f53 \u7531\u51fd\u6570\u5728\u6570\u636e\u5e93\u5b8c\u6210<br \/>\n}<\/p>\n<p>src\/client\/main.cpp<\/p>\n<p>\/\/ \u63a7\u5236\u804a\u5929\u9875\u9762&#8211;\u6ce8\u9500\u9700\u8981\u9000\u51fa\u804a\u5929\u9875\u9762<br \/>\nbool isMainMenuRunning &#061; false;<\/p>\n<p>\/\/ \u767b\u5f55\u6210\u529f, \u542f\u52a8\u63a5\u6536\u7ebf\u7a0b&#8212;-\u53ea\u8981\u5ba2\u6237\u7aef \u4e0d\u5b8c\u5168\u9000\u51fa, \u5c31\u53ea\u542f\u52a8\u4e00\u6b21!<br \/>\nstatic int threadnum &#061; 0;<br \/>\nif (threadnum &#061;&#061; 0)<br \/>\n{<br \/>\n    std::thread readTask(readTaskHandler, clientfd); \/\/ thread \u652f\u6301\u8de8\u5e73\u53f0<br \/>\n    readTask.detach();<br \/>\n}<\/p>\n<p>\/\/ \u5206\u79bb\u7ebf\u7a0b, \u8ba9\u5176\u72ec\u7acb\u8fd0\u884c, \u4e0d\u963b\u585e\u4e3b\u7ebf\u7a0b<\/p>\n<p>\/\/ \u4e3b\u7ebf\u7a0b\u7ee7\u7eed\u6267\u884c, \u8fdb\u5165\u804a\u5929\u83dc\u5355\u9875\u9762<br \/>\nisMainMenuRunning &#061; true;<br \/>\nmainMenu(clientfd);<\/p>\n<p>\/\/ \u5220\u9664 return 0;<\/p>\n<p>\/\/ \u4e3b\u9875\u9762\u804a\u5929\u7a0b\u5e8f<br \/>\nvoid mainMenu(int clientfd)<br \/>\n{<br \/>\n    help();<br \/>\n    \/\/ for (;;)<br \/>\n    while (isMainMenuRunning)<br \/>\n    {&#8230;}<br \/>\n}<\/p>\n<p>\/\/ quit\u51fd\u6570<br \/>\nvoid quit(int clientfd, string msg)<br \/>\n{<\/p>\n<p>    json js;<br \/>\n    js[&#034;msgid&#034;] &#061; LOGINOUT_MSG;       \/\/ \u6ce8\u9500\u6d88\u606f<br \/>\n    js[&#034;id&#034;] &#061; g_currentUser.getId(); \/\/ \u5f53\u524d\u767b\u5f55\u7528\u6237id<\/p>\n<p>    string request &#061; js.dump();                                                \/\/ json\u8f6c\u5b57\u7b26\u4e32  \u5e8f\u5217\u5316<br \/>\n    int len &#061; send(clientfd, request.c_str(), strlen(request.c_str()) &#043; 1, 0); \/\/ \u53d1\u9001\u6570\u636e<br \/>\n    if (len &lt; 0)<br \/>\n    {<br \/>\n        cerr &lt;&lt; &#034;send quit msg error: &#034; &lt;&lt; request &lt;&lt; endl;<br \/>\n    }<br \/>\n    isMainMenuRunning &#061; false; \/\/ \u9000\u51fa\u804a\u5929\u9875\u9762<br \/>\n    \/\/ close(clientfd);  \u653e\u5728\u670d\u52a1\u7aef\u5904\u7406<br \/>\n    \/\/ exit(0);<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb957\u6b21\uff0c\u70b9\u8d5e19\u6b21\uff0c\u6536\u85cf24\u6b21\u3002\u5ba2\u6237\u7aef\u7fa4\u7ec4, \u7528\u6237\u6ce8\u9500, \u6d4b\u8bd5, \u9519\u8bef\u89e3\u51b3<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[230,2382,43,78],"topic":[],"class_list":["post-33896","post","type-post","status-publish","format-standard","hentry","category-server","tag-php","tag-2382","tag-43","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e03) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/33896.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e03) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb957\u6b21\uff0c\u70b9\u8d5e19\u6b21\uff0c\u6536\u85cf24\u6b21\u3002\u5ba2\u6237\u7aef\u7fa4\u7ec4, \u7528\u6237\u6ce8\u9500, \u6d4b\u8bd5, \u9519\u8bef\u89e3\u51b3\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/33896.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-28T09:40:39+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/33896.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/33896.html\",\"name\":\"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e03) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-28T09:40:39+00:00\",\"dateModified\":\"2025-04-28T09:40:39+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/33896.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/33896.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/33896.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e03)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e03) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/33896.html","og_locale":"zh_CN","og_type":"article","og_title":"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e03) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb957\u6b21\uff0c\u70b9\u8d5e19\u6b21\uff0c\u6536\u85cf24\u6b21\u3002\u5ba2\u6237\u7aef\u7fa4\u7ec4, \u7528\u6237\u6ce8\u9500, \u6d4b\u8bd5, \u9519\u8bef\u89e3\u51b3","og_url":"https:\/\/www.wsisp.com\/helps\/33896.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-28T09:40:39+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/33896.html","url":"https:\/\/www.wsisp.com\/helps\/33896.html","name":"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e03) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-28T09:40:39+00:00","dateModified":"2025-04-28T09:40:39+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/33896.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/33896.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/33896.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u65bd\u78ca\u8001\u5e08\u57fa\u4e8emuduo\u7f51\u7edc\u5e93\u7684\u96c6\u7fa4\u804a\u5929\u670d\u52a1\u5668(\u4e03)"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/33896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=33896"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/33896\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=33896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=33896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=33896"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=33896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}