{"id":87703,"date":"2020-05-14T09:58:33","date_gmt":"2020-05-14T01:58:33","guid":{"rendered":"http:\/\/4563.org\/?p=87703"},"modified":"2020-05-14T09:58:33","modified_gmt":"2020-05-14T01:58:33","slug":"android-%e7%9a%84-socket-%e6%8e%a5%e6%94%b6%e5%9b%be%e7%89%87%ef%bc%8c%e5%8f%aa%e6%88%90%e5%8a%9f%e4%b8%80%e6%ac%a1%ef%bc%8c%e6%98%af%e5%93%aa%e9%87%8c%e5%86%99%e9%94%99%e4%ba%86%e5%90%97%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=87703","title":{"rendered":"Android \u7684 Socket \u63a5\u6536\u56fe\u7247\uff0c\u53ea\u6210\u529f\u4e00\u6b21\uff0c\u662f\u54ea\u91cc\u5199\u9519\u4e86\u5417\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Android \u7684 Socket \u63a5\u6536\u56fe\u7247\uff0c\u53ea\u6210\u529f\u4e00\u6b21\uff0c\u662f\u54ea\u91cc\u5199\u9519\u4e86\u5417\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : atfeel <\/span>  <span><i><\/i> 7<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>Android \u7684 Socket \u63a5\u6536\u56fe\u7247\uff0c\u7b2c\u4e00\u6b21\u63a5\u6536\u56fe\u7247\u4f1a\u5728 inStream.read(buffer)\u8fd9\u884c\u963b\u585e\u7b49\u5f85\u6570\u636e\uff0c\u6b63\u5e38\u63a5\u6536\u5230\u56fe\u7247\u540e\uff0c\u7b2c\u4e8c\u6b21\u63a5\u6536\u56fe\u7247\uff0c\u8fd9\u53e5\u76f4\u63a5\u8fd4\u56de-1\uff0c\u4e0d\u963b\u585e\u4e86\uff0c\u6240\u4ee5\u8fd9\u6bb5\u4ee3\u7801\u53ea\u80fd\u8bd5\u4e00\u6b21\u6027\u7684\uff0c\u5982\u4f55\u8ba9\u4ed6\u63a5\u6536\u5b8c\u7b2c\u4e00\u5f20\u56fe\u540e\uff0c\u7ee7\u7eed\u7b49\u5f85\u7b2c\u4e8c\u5f20\u56fe\u5462\uff0c\u8fd9\u4e2a\u5faa\u73af\u63a5\u6536\u600e\u4e48\u5199\u7684\u3002<\/p>\n<p>https:\/\/github.com\/atfeel\/test_Sock_Loop_Send_Pic<\/p>\n<p>\u6211\u5c31\u662f\u60f3\u5b9e\u73b0 \u4e0d\u5173\u95ed\u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\uff0c\u670d\u52a1\u7aef\u5faa\u73af\u63a5\u6536\u5ba2\u6237\u7aef\u53d1\u9001\u7684\u56fe\u7247\u3002<\/p>\n<p>\u54ea\u4f4d V \u53cb\u80fd\u5e2e\u8c03\u6574\u4e0b\u5417\uff1f\u6211\u5f04\u4e86\u534a\u5929\u6ca1\u641e\u660e\u767d<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>12<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1467167\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : atfeel <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u73b0\u5728\u53ef\u4ee5\u786e\u8ba4\u4e00\u70b9\u662f\uff0cwhile \u5faa\u73af\uff0c\u7b2c\u4e00\u6b21\u6267\u884c\u5230 inStream.read(buffer)\u7684\u65f6\u5019\uff0c\u540e\u963b\u585e\u5728\u8fd9\u53e5\uff0c\u76f4\u5230\u5ba2\u6237\u7aef\u53d1\u9001\u6570\u636e\uff0c\u624d\u4f1a\u5f80\u4e0b\u6267\u884c\u3002<\/p>\n<p>\u4f46\u662f\u5173\u952e\u662f\uff0c\u5904\u7406\u5b8c\u7b2c\u4e00\u6b21\u540e\uff0c\u65b0\u7684\u4e00\u8f6e while \u5faa\u73af\u5230 inStream.read(buffer)\u7684\u65f6\u5019\u548c\u7b2c\u4e00\u6b21\u4e0d\u4e00\u6837\uff0c\u4e0d\u963b\u585e\u4e86\uff0c\u7406\u89e3\u4e0d\u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1467168\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : n770011 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u5ba2\u670d\u7aef\u53d1\u9001\u6570\u636e\u540e\u5c31 close\uff0c\u65e2\u7136\u90fd\u628a client \u5168\u5c40\u5316\u4e86\uff0c\u5c31\u4e0d\u8be5\u5728\u4e00\u6b21\u4e1a\u52a1\u4e2d\u53bb close client \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1467169\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jinhan13789991 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             129 \u884c\uff0cos.close(); \u4f60\u90fd\u5173\u95ed\u4e86\u8fd8\u600e\u4e48\u63a5\u6536\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1467170\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : atfeel <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jinhan13789991 \u53bb\u6389\u4e86 os.close();\u53d1\u9001\u90fd\u4e0d\u6210\u529f\u4e86\uff01\uff01                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1467171\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zoharSoul <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @atfeel \u4e0d\u8981\u6fc0\u52a8!!!                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1467172\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fdppzrl <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             line106 stream.close \u7684\u95ee\u9898\u3002 \u505a\u6807\u8bb0\u9000\u51fa\u5faa\u73af\u518d\u5173\u3002\u6216\u8005 try-catch-finally \u518d\u5173                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1467173\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : atfeel <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @fdppzrl \u4e0d\u662f\u5462                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1467174\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : atfeel <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @n770011 \u53bb\u6389\u4e86 os.close();\u53d1\u9001\u90fd\u4e0d\u6210\u529f\u4e86\uff01\uff01\u6ca1\u53bb\u6389\u7684\u8bdd\u7b2c\u4e00\u6b21\u8fd8\u662f\u6210\u529f\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1467175\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : CommandZi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u611f\u89c9\u4f60\u8fd8\u6ca1\u7406\u89e3\u7f51\u7edc\u5b57\u8282\u6d41\u7684\u5de5\u4f5c\u65b9\u5f0f\uff0c<br \/>\u4f60\u53ef\u4ee5\u81ea\u5df1\u5b9a\u4e49\u4e00\u4e2a\u7ed3\u675f\u7b26\u53f7\u8ddf\u5728\u56fe\u7247\u540e\u9762\uff0c\u9047\u5230\u7ed3\u675f\u7b26\u53f7\u5c31\u8bfb\u53d6\u4e0b\u4e00\u6bb5\u6570\u636e\uff0c<br \/>\u6216\u8005\u5728\u56fe\u7247\u6570\u636e\u524d\u9762\u7528\u56fa\u5b9a\u4e2a\u5b57\u8282\u5b9a\u4e49\u56fe\u7247\u7684\u6570\u636e\u957f\u5ea6\uff0c\u5148\u8bfb\u957f\u5ea6\u518d\u6839\u636e\u957f\u5ea6\u8bfb\u53d6\u56fe\u7247\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1467176\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jinhan13789991 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0a\u6b63\u89e3\uff0c\u539f\u56e0\u5c31\u662f\u4f60\u7684\u7a0b\u5e8f\u6b63\u786e\u533a\u5206\u4e24\u5f20\u56fe\u7247\u5185\u5bb9\u3002<br \/>\u53ef\u4ee5\u628a 129 \u884c\u7684 os.close(); \u6ce8\u9500\u6389\u3002\u7136\u540e\u624b\u52a8\u53d1\u9001\u56fe\u7247\uff0c\u7b49\u7b2c\u4e00\u5f20\u56fe\u7247\u63a5\u6536\u6210\u529f\u4e86\u3002\u7b49\u4e00\u4f1a\u518d\u53d1\u9001\u7b2c\u4e8c\u5f20\u3002<br \/>\u8fd9\u662f\u901a\u8fc7\u65f6\u95f4\u6765\u5206\u5272\u4e24\u5f20\u56fe\u7247\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1467177\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : AoEiuV020 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             close \u6362 flush \u5462\uff0c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1467178\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : AoEiuV020 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u662f\uff0c\u770b\u4e86\u4e0b\u4ee3\u7801\uff0c\u76f4\u63a5\u5220\u9664 close \u7684\u8bdd\uff0c\u670d\u52a1\u7aef\u5c31\u53ef\u4ee5\u7ee7\u7eed\u8bfb\u4e86\uff0c\u7ee7\u7eed\u963b\u585e\u5728 read, \u4f60\u5c45\u7136\u6ca1\u6709\u4efb\u4f55\u5176\u4ed6\u8df3\u51fa\u5faa\u73af\u7684\u6761\u4ef6\u5417\uff1f<br \/>\u4e00\u76f4\u5361\u5728 read \u4e0d\u4e0b\u53bb\u5f53\u7136\u4e0d\u4f1a\u663e\u793a\u6536\u5230\u56fe\u7247\u4e86\uff0c<br \/>\u6700\u7b80\u5355\u505a\u6cd5\u662f\u7ea6\u5b9a\u4e00\u4e2a\u7b80\u5355\u534f\u8bae\uff0c\u6bd4\u8f83\u4e00\u5f00\u59cb 4 \u4e2a\u5b57\u8282\u8868\u793a\u4e0b\u4e00\u5f20\u56fe\u7247\u7684\u5927\u5c0f\uff0c\u670d\u52a1\u7aef\u6536\u5230\u8fd9\u4e48\u591a\u5b57\u8282\u5c31\u505c\u6b62 read \u8df3\u51fa\u5faa\u73af\u663e\u793a\u56fe\u7247\uff0c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Android \u7684 Socket &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\/87703"}],"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=87703"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/87703\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=87703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=87703"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=87703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}