{"id":3214,"date":"2011-08-11T12:07:01","date_gmt":"2011-08-11T04:07:01","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=3214"},"modified":"2011-08-11T12:07:01","modified_gmt":"2011-08-11T04:07:01","slug":"%e5%9f%ba%e4%ba%8esocket-api%e7%9a%84cs%e9%80%9a%e4%bf%a1%ef%bc%9a%e4%bb%a5%e6%a0%91%e5%bd%a2%e7%bb%93%e6%9e%84%e6%98%be%e7%a4%ba%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%ab%af%e7%9b%ae%e5%bd%952","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/3214","title":{"rendered":"\u57fa\u4e8eSocket API\u7684C\/S\u901a\u4fe1\uff1a\u4ee5\u6811\u5f62\u7ed3\u6784\u663e\u793a\u670d\u52a1\u5668\u7aef\u76ee\u5f55(2)"},"content":{"rendered":"<h4>3.\u5ba2\u6237\u7aef\u7684\u5b9e\u73b0<\/h4>\n<p>\u7531\u4e8e\u5ba2\u6237\u7aef\u91c7\u7528\u9762\u5411\u5bf9\u8c61\u7684Qt\u6765\u7f16\u7801\uff0c\u56e0\u6b64\u5ba2\u6237\u7aef\u6bd4\u8f83\u5bb9\u6613\u5b9e\u73b0\u3002\u5ba2\u6237\u7aef\u7684\u4e3b\u8981\u529f\u80fd\u662f\uff1a\u4ee5\u5217\u8868\u5f62\u5f0f\u663e\u793a\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u4ee5\u53ca\u76f8\u5173\u5c5e\u6027\uff1b\u5f53\u7528\u6237\u70b9\u51fb\u6587\u4ef6\u5217\u8868\u4e2d\u7684\u67d0\u4e2a\u76ee\u5f55\u65f6\u8fdb\u5165\u8be5\u5b50\u76ee\u5f55\uff0c\u5e76\u663e\u793a\u5b50\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u5217\u8868\uff1b\u53ef\u4ee5\u8fd4\u56de\u5230\u5f53\u524d\u76ee\u5f55\u7684\u7236\u76ee\u5f55\u3002<\/p>\n<p>\u6839\u636e\u4e0a\u8ff0\u9700\u6c42\uff0c\u5ba2\u6237\u7aef\u7684\u754c\u9762\u8bbe\u8ba1\u53ef\u4ee5\u53c2\u8003\u4e0b\u56fe\uff0c\u5373\u901a\u8fc7\u4e00\u4e2aQTableWidget\u6765\u663e\u793a\u67d0\u4e2a\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\uff0c\u8be5\u90e8\u4ef6\u7684\u4f7f\u7528\u65b9\u6cd5\u53ef\u4ee5\u53c2\u8003Qt Assitant\u3002<br \/>\n<a href=\"http:\/\/edsionte.com\/techblog\/archives\/3214\/screenshot-9\" rel=\"attachment wp-att-3217\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3217\" title=\"Screenshot\" src=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2011\/08\/Screenshot-300x173.png\" alt=\"\" width=\"300\" height=\"173\" srcset=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2011\/08\/Screenshot-300x173.png 300w, http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2011\/08\/Screenshot.png 604w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n\u63a5\u4e0b\u6765\u91cd\u70b9\u8bf4\u660e\u901a\u4fe1\u90e8\u5206\u7684\u529f\u80fd\u5b9e\u73b0\u3002\u5728\u670d\u52a1\u5668\u7a0b\u5e8f\u4e2d\uff0c\u670d\u52a1\u5668\u5411\u5ba2\u6237\u7aef\u53d1\u9001\u7684\u6570\u636e\u6709\u4e24\u79cd\uff0c\u4e00\u79cd\u5373\u4e3a\u6587\u4ef6\u6570\uff0c\u53e6\u4e00\u79cd\u5219\u4e3a\u6240\u6709\u6587\u4ef6\u4fe1\u606f\u5f62\u6210\u7684\u5b57\u8282\u6d41\u3002\u90a3\u4e48\u5728\u5ba2\u6237\u7aef\u4e2d\u5219\u76f8\u5e94\u7684\u6709\u63a5\u53d7\u51fd\u6570recvDirInfo()\u3002<\/p>\n<pre class=\"brush:c\">void configShowUI::recvDirInfo()\r\n{\r\n    \/\/1.\u5148\u63a5\u53d7\u6307\u5b9a\u76ee\u5f55\u4e0b\u6587\u4ef6\u7684\u6570\u76ee\r\n    int fileNum = 0;\r\n    if (cli.recvData(&amp;fileNum, sizeof(int)) == 0) {\r\n        ui-&gt;statusLabel-&gt;setText(\"ERROR:receive fileNum error!\");\r\n    }\r\n\r\n    \/\/2.\u63a5\u6536\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u540d\u5e8f\u5217\r\n    char *dirbuf = NULL;\r\n    if ((dirbuf = (char *)malloc(DATA_MAX * 10)) == NULL) {\r\n        ui-&gt;statusLabel-&gt;setText(\"ERROR:malloc error!\");\r\n    }\r\n    memset(dirbuf, 0, DATA_MAX * 10);\r\n    if (cli.recvData(dirbuf, DATA_MAX * 10) == 0) {\r\n        ui-&gt;statusLabel-&gt;setText(\"ERROR:receive dir info error!\");\r\n    } else {\r\n        ui-&gt;statusLabel-&gt;setText(\"receive dir info success!\");\r\n        this-&gt;printCurDir(QString(dirbuf), fileNum);\r\n        free(dirbuf);\r\n    }\r\n}<\/pre>\n<p>\u8be5\u51fd\u6570\u6709\u4e24\u79cd\u4f7f\u7528\u573a\u666f\uff0c\u5176\u4e00\u4e3a\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u8fde\u63a5\u6210\u529f\u65f6\uff0c\u6b64\u65f6\u670d\u52a1\u5668\u8981\u5411\u5ba2\u6237\u7aef\u53d1\u9001\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u5217\u8868\uff08\u670d\u52a1\u5668\u4e3b\u52a8\u53d1\u9001\uff09\uff0c\u56e0\u6b64\u5e94\u8be5\u8c03\u7528\u8be5\u51fd\u6570\u3002\u5176\u4e8c\u4e3a\u5f53\u7528\u6237\u5728\u5ba2\u6237\u7aef\u7684\u6587\u4ef6\u5217\u8868\u4e2d\u70b9\u51fb\u67d0\u4e2a\u5b50\u76ee\u5f55\u65f6\uff0c\u5ba2\u6237\u7aef\u6b64\u65f6\u4e3b\u52a8\u8981\u6c42\u670d\u52a1\u5668\u53d1\u9001\u6307\u5b9a\u5b50\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u5217\u8868\uff08\u670d\u52a1\u5668\u88ab\u52a8\u53d1\u9001\uff09\uff0c\u6b64\u65f6\u5e94\u8be5\u8c03\u7528\u8be5\u51fd\u6570\u3002<\/p>\n<p>\u7b2c\u4e8c\u79cd\u60c5\u666f\u53ef\u4ee5\u91c7\u7528Qt\u4e2d\u7684\u4fe1\u53f7&#8211;\u69fd\u673a\u5236\uff08\u53ef\u4ee5\u53c2\u8003Qt Assitant\u4e86\u89e3\u76f8\u5173\u6982\u5ff5\uff09\uff0c\u5f53\u7528\u6237\u70b9\u51fb\u4e86\u6587\u4ef6\u5217\u8868\u4e2d\u7684\u67d0\u4e2a\u5b50\u76ee\u5f55\u65f6\uff0c\u8be5\u5217\u8868\u90e8\u4ef6\uff08fileWidget\uff09\u5c31\u53d1\u9001cdNextDir(QString)\u4fe1\u53f7\uff08\u8be5\u4fe1\u53f7\u5728\uff09\uff0c\u5305\u542b\u5217\u8868\u90e8\u4ef6\u7684\u5f53\u524d\u90e8\u4ef6\uff08this\uff09\u63a5\u6536\u5230\u8fd9\u4e2a\u4fe1\u53f7\u540e\u5c31\u505a\u51fa\u76f8\u5e94\u64cd\u4f5c\uff0c\u5373\u6267\u884c\u69fd\u51fd\u6570cdNextDirOperation(QString)\u3002\u8fd9\u5bf9\u4fe1\u53f7\u548c\u69fd\u4e4b\u95f4\u8fd8\u4f20\u9012\u4e86pathname\u8fd9\u4e2a\u53d8\u91cf\uff0c\u8be5\u53d8\u91cf\u5b58\u50a8\u4e86\u5b50\u76ee\u5f55\u7684\u5b8c\u6574\u8def\u5f84\u3002\u4e0b\u9762\u7684\u8fde\u63a5\u51fd\u6570\u5e94\u8be5\u5728\u5f53\u524d\u90e8\u4ef6\u7684\u6784\u9020\u51fd\u6570\u4e2d\u5b8c\u6210\u3002<\/p>\n<pre class=\"brush:c\">    connect(this-&gt;fileWidget, SIGNAL(cdNextDir(QString)), this, SLOT(cdNextDirOperation(QString)));<\/pre>\n<p>\u69fd\u51fd\u6570cdNextDirOperation(QString)\u6307\u5b9a\u7684\u52a8\u4f5c\u5f88\u7b80\u5355\uff0c\u5373\u5148\u5411\u670d\u52a1\u5668\u53d1\u9001\u201c\u8bfb\u53d6\u4e0b\u7ea7\u76ee\u5f55\u201d\u7684\u6307\u4ee4\uff0c\u518d\u5c06\u8be5\u5b50\u76ee\u5f55\u7684\u5b8c\u6574\u8def\u5f84\u53d1\u9001\u5230\u670d\u52a1\u5668\u7aef\uff0c\u63a5\u7740\u518d\u8c03\u7528recvDirInfo()\u3002\u53ef\u4ee5\u770b\u5230\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u6570\u636e\u4ea4\u4e92\u662f\u540c\u6b65\u53d1\u751f\u7684\u3002<\/p>\n<pre class=\"brush:c\">void configShowUI::cdNextDirOperation(QString pathname)\r\n{\r\n    char cd[] = \"cd\";\r\n    if (cli.sendData(cd, strlen(cd)) == 0) {\r\n        ui-&gt;statusLabel-&gt;setText(\"ERROR: send cd command error!\");\r\n        exit(1);\r\n    }\r\n\r\n    if (cli.sendData(pathname.toUtf8().data(), pathname.size()) == 0) {\r\n        ui-&gt;statusLabel-&gt;setText(\"ERROR: send pathname error!\");\r\n        exit(1);\r\n    }\r\n\r\n    this-&gt;recvDirInfo();\r\n}<\/pre>\n<p>\u5728\u4e0a\u8ff0\u7684recvDirInfo()\u4e2d\uff0c\u5982\u679c\u5ba2\u6237\u7aef\u6210\u529f\u63a5\u6536\u4e86\u670d\u52a1\u5668\u53d1\u9001\u7684\u5b57\u8282\u6d41\u6570\u636e\uff0c\u90a3\u4e48\u5c31\u8c03\u7528printCurDir()\u5bf9\u5b57\u8282\u6d41\u8fdb\u884c\u89e3\u6790\uff0c\u7136\u540e\u4ee5\u5217\u8868\u5f62\u5f0f\u663e\u793a\u5728\u5ba2\u6237\u7aef\u3002\u8fd9\u91cc\u7684\u89e3\u6790\u8fc7\u7a0b\u7531\u5177\u4f53\u7684\u9700\u6c42\u800c\u5b9a\uff0c\u518d\u6b21\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>3.\u5ba2\u6237\u7aef\u7684\u5b9e\u73b0 \u7531\u4e8e\u5ba2\u6237\u7aef\u91c7\u7528\u9762\u5411\u5bf9\u8c61\u7684Qt\u6765\u7f16\u7801\uff0c\u56e0\u6b64\u5ba2\u6237\u7aef\u6bd4\u8f83\u5bb9\u6613\u5b9e\u73b0\u3002\u5ba2\u6237\u7aef\u7684\u4e3b\u8981\u529f\u80fd\u662f\uff1a\u4ee5\u5217\u8868\u5f62\u5f0f\u663e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[208],"tags":[241,200,209,242],"class_list":["post-3214","post","type-post","status-publish","format-standard","hentry","category-208","tag-api","tag-qt","tag-socket","tag-tcpip"],"views":5715,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=3214"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3214\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=3214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=3214"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=3214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}