{"id":220985,"date":"2020-11-21T02:32:48","date_gmt":"2020-11-20T18:32:48","guid":{"rendered":"http:\/\/4563.org\/?p=220985"},"modified":"2020-11-21T02:32:48","modified_gmt":"2020-11-20T18:32:48","slug":"nodejs-%e7%9a%84-socket-%e6%98%af%e6%80%8e%e4%b9%88%e5%9b%9e%e4%ba%8b","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=220985","title":{"rendered":"nodejs \u7684 socket \u662f\u600e\u4e48\u56de\u4e8b"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  nodejs \u7684 socket \u662f\u600e\u4e48\u56de\u4e8b               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zxCoder <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>server.on('connection', (client) =&gt; {         client.on('data', (msg)=&gt; {         });         client.on('error',  (e)=&gt; {             client.end();         });         client.on( 'close', ()=&gt; {             console.log(`\u5ba2\u6237\u7aef\u4e0b\u7ebf\u4e86`);         });     }); <\/code><\/pre>\n<p>\u600e\u4e48\u50cf\u522b\u7684\u8bed\u8a00\u4e00\u6837\uff0c\u4e0d\u662f\u8981\u5b9a\u4e49\u4e00\u4e2a\u7f13\u51b2\u533a\u5417\uff0c\u7136\u540e\u7f13\u51b2\u533a\u6ee1\u518d\u8bfb\u53d6\u6570\u636e\u89e3\u6790\uff0c\u8fd9\u91cc\u76f4\u63a5\u5728 data \u4e8b\u4ef6\u4e2d\u63a5\u6536\u6570\u636e\u662f\u4ec0\u4e48\u610f\u601d\uff0c\u5ba2\u6237\u7aef\u5982\u679c for \u5faa\u73af\u53d1\u9001\uff0c\u670d\u52a1\u7aef\u8981\u600e\u4e48\u63a5\u6536\u5462<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4448763\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : echowuhao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             node js event loop \u5b66\u4e60\u4e00\u4e0b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4448764\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ruoxie <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/www.barretlee.com\/blog\/2017\/06\/06\/dive-to-nodejs-at-stream-module\/                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4448765\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : borisz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u670d\u52a1\u5668\u7aef\u7684\u786e\u662f\u4f1a\u6709\u65f6\u5019\u63a5\u6536\u591a,\u6709\u65f6\u5019\u5c11\u7684, \u9700\u8981\u81ea\u5df1\u7f13\u5b58\u5207\u5206                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4448766\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cheneydog <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u90fd\u662f\u8fd9\u6837\u4e48\uff1f\u54ea\u4e2a\u8bed\u8a00\u96be\u9053\u4f1a\u5e2e\u4f60\u81ea\u52a8\u5206\u5305\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4448767\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd0\u884c\u65f6\u5e2e\u4f60\u5efa\u8bae\u7f13\u51b2\u533a\u3001\u8bfb\u53d6\u4e86\u4e0d\u5c11\u4fe1\u606f\uff0c\u7136\u540e\u628a\u7f13\u51b2\u533a\u7684\u5185\u5bb9\u5efa\u7acb\u6210 msg \u4f20\u7ed9\u4f60\u7684\u51fd\u6570\uff0c\u7136\u540e\u4f60\u8fd8\u9700\u8981\u518d\u5efa\u4e00\u4e2a\u7f13\u51b2\u533a\u53bb\u4fdd\u5b58\u8fd9\u4e9b msg \u5e76\u4e14\u89e3\u6790 \u2014\u2014 \u5f53\u7136\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\u62fc\u63a5\u5b57\u7b26\u4e32\u4e86\u4e8b\u3002<\/p>\n<p>\u53ef\u80fd\u4f60\u6ca1\u660e\u767d on \u6ce8\u518c\u56de\u8c03\u7684\u610f\u601d\uff0c\u4f60\u7684\u8fd9\u4e2a on \u8fdb\u53bb\u7684 (msg) =&gt; {} \u662f\u4e00\u4e2a\u88ab\u4fdd\u5b58\u5e76\u53ef\u53cd\u590d\u8c03\u7528\u7684\u56de\u8c03\u51fd\u6570\u3002\u5982\u679c\u5ba2\u6237\u7aef\u53d1\u9001\u4e86\u4e0d\u5c11\uff0c\u4f60\u7684\u56de\u8c03\u51fd\u6570\u4f1a\u88ab\u8c03\u7528\u591a\u6b21\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4448768\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Mutoo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7c98\u5305\u8b66\u5bdf\u5462 :doge:                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4448769\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : viakiba <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             length key payload                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>nodejs \u7684 socket \u662f&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/220985"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=220985"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/220985\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=220985"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=220985"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=220985"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}