{"id":99085,"date":"2020-05-22T02:04:42","date_gmt":"2020-05-21T18:04:42","guid":{"rendered":"http:\/\/4563.org\/?p=99085"},"modified":"2020-05-22T02:04:42","modified_gmt":"2020-05-21T18:04:42","slug":"android-%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87-socket-%e9%ab%98%e6%95%88%e7%8e%87%e5%8f%91%e9%80%81-int-%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=99085","title":{"rendered":"Android \u5982\u4f55\u901a\u8fc7 Socket \u9ad8\u6548\u7387\u53d1\u9001 int \u6570\u7ec4"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Android \u5982\u4f55\u901a\u8fc7 Socket \u9ad8\u6548\u7387\u53d1\u9001 int \u6570\u7ec4               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : atfeel <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>Android \u5982\u4f55\u901a\u8fc7 Socket \u9ad8\u6548\u7387\u53d1\u9001 int \u6570\u7ec4<\/p>\n<p>\u53d1\u9001\u7aef\u60f3\u628a bitmap \u53d1\u9001\u7ed9\u63a5\u6536\u7aef\u3002<\/p>\n<p>\u63a5\u6536\u7aef\u53ea\u9700\u8981 bitmap \u7684 int[]\u6570\u636e<\/p>\n<p>\u4e0b\u9762\u4ee3\u7801\u662f\u53d1\u9001\u7aef\u628a bitmap \u8f6c\u6210 int[]<\/p>\n<p>int[] data = new int[width*height];<\/p>\n<p>bitmap.getPixels(data, 0, width, 0, 0, width, height);<\/p>\n<p>\u5982\u4f55\u628a\u8fd9\u4e2a int[] data \u53d1\u9001\u7ed9\u63a5\u6536\u7aef\u3002<\/p>\n<p>\u6570\u636e\u91cf\u5927\u7ea6\u662f 80,0000 \u7684\u957f\u5ea6<\/p>\n<p>Socket \u4e0d\u80fd\u76f4\u63a5\u53d1\u9001 int[]<\/p>\n<p>\u6211\u8bd5\u8fc7\u628a int[]\u8f6c\u6210 byte[]\u5728\u53d1\u9001\uff0c\u4f46\u662f\u8f6c\u6362\u82b1\u7684\u65f6\u95f4\u592a\u957f\uff0c\u8981\u6c42\u5728 5ms \u4ee5\u5185<\/p>\n<p>\u5982\u679c\u6211\u76f4\u63a5\u628a bitmap \u8f6c\u6210 byte[]<\/p>\n<p>byte[] data = new int[width*height];<\/p>\n<p>bitmap.compress(Bitmap.CompressFormat.JPEG, 100, data);<\/p>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u4f1a\u597d\u4e00\u70b9\uff0c\u4f46\u662f\u4e5f\u8981\u82b1 30ms \u5de6\u53f3\uff0c\u8fbe\u4e0d\u5230\u6211\u7684\u8981\u6c42\u3002<\/p>\n<p>\u5982\u679c\u53d1\u9001\u7684\u662f byte[]\uff0c\u63a5\u6536\u7aef\u8fd8\u5f97\u8f6c\u56de int[]\u624d\u80fd\u7528\uff0c\u4e5f\u592a\u8017\u65f6<\/p>\n<p>\u6211\u7684\u63a5\u6536\u7aef\u53ea\u60f3\u8981 bitmap \u7684 int[]\uff0c\u8c01\u6709\u4ec0\u4e48\u529e\u6cd5\u5417\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>18<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1647997\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : stonefeng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c socket \u662f\u57fa\u4e8e udp \u534f\u8bae\u7684\u8bdd\uff0c\u6bcf\u4e2a\u6570\u636e\u5305\u7684\u6700\u5927\u5bb9\u91cf\u662f 1472 \u5b57\u8282\uff08\u5305\u542b header \uff09\uff0c800,000 \u5b57\u8282\u7684\u957f\u5ea6\u80af\u5b9a\u662f\u65e0\u6cd5\u5355\u4e2a\u6570\u636e\u5305\u4f20\u8f93\u8fc7\u53bb\u7684\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 redis\uff0c\u8fd9\u8fb9\u5b58\uff0c\u90a3\u8fb9\u53d6\uff0c\u907f\u514d\u4e86 upd \u6570\u636e\u5305\u5bb9\u91cf\u7684\u9650\u5236\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1647998\" 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>                                                             @stonefeng \u73b0\u5728\u5df2\u7ecf\u4e0d\u662f\u534f\u8bae\u548c\u53d1\u9001\u5931\u8d25\u7684\u95ee\u9898\uff0c\u662f\u53d1\u9001\u6548\u7387\u7684\u95ee\u9898                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1647999\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : rrfeng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5565 socket \uff1f\u901a\u8fc7\u7f51\u7edc\u5417\uff1f\u8fd8\u662f\u672c\u673a\uff1f\u8fd8\u662f\u5c40\u57df\u7f51\uff1f<\/p>\n<p>800000bytes\/5ms = 160MBps <\/p>\n<p>\u96be                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648000\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : asAnotherJack <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6807\u9898\u95ee\u7684\u662f\u4f20\u8f93\u6548\u7387\uff0c\u6b63\u6587\u597d\u50cf\u8bf4\u7684\u662f\u8f6c\u6362\u6548\u7387<br \/>\u4e3a\u4ec0\u4e48\u8981\u6c42\u4e00\u5b9a\u63a7\u5236\u5728 5ms \u5462\uff0c\u56fe\u7247\u5927\u7684\u8bdd\u8f6c\u6362\u65f6\u95f4\u53d8\u957f\u4e5f\u6b63\u5e38\uff0c\u5982\u679c\u662f\u9632\u6b62\u5ba2\u6237\u7aef\u5361\u987f\u53ef\u4ee5\u628a\u8f6c\u6362\u8fc7\u7a0b\u653e\u5230\u5b50\u7ebf\u7a0b\uff0c\u4e3b\u7ebf\u7a0b\u52a0\u4e2a loading \u6846                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648001\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : stonefeng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @atfeel socket \u672c\u8eab\u662f\u4e00\u79cd\u9ad8\u6548\u7387\u7684\u6570\u636e\u4f20\u8f93\u65b9\u5f0f\uff0c\u5982\u679c\u4f60\u8981\u901a\u8fc7 socket \u4f20\u8f93 800,000 \u5b57\u8282\u957f\u5ea6\u7684\u6570\u636e\u7684\u8bdd\uff0c\u6211\u5efa\u8bae\u4f60\u5bf9\u5728\u53d1\u9001\u7aef\u5bf9\u6570\u636e\u8fdb\u884c\u62c6\u5305\uff0c\u5728\u63a5\u6536\u7aef\u8fdb\u884c\u6574\u5408\uff0c\u4f46\u662f\u6ce8\u610f upd \u534f\u8bae\u5728\u6570\u636e\u5b8c\u6574\u6027\u4e0a\u4e0d\u5982 tcp\uff0c\u8981\u5728\u6574\u5408\u65f6\u8981\u68c0\u6d4b\u6570\u636e\u6389\u5305\uff0c\u5982\u679c\u6570\u636e\u4e0d\u5b8c\u6574\u5219\u9700\u8981\u6709\u91cd\u8bd5\u673a\u5236                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648002\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : May725 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e3b\u8fd8\u662f\u8bf4\u4e0b\u539f\u59cb\u9700\u6c42\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648003\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : iceheart <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             800k\/5ms = 160M \u5b57\u8282 \/\u79d2\uff0c<br \/>\u518d\u8003\u8651\u7f51\u7edc\u6ce2\u52a8\uff0c\u6211\u5224\u65ad\u4f60\u7684\u9700\u6c42\u5e94\u8be5\u662f\u672c\u673a\u6570\u636e\u4f20\u8f93\uff0c\u5426\u5219\u6ca1\u6cd5\u5b9e\u73b0\u3002<br \/>\u672c\u673a\u4f20\u8f93\u53ef\u4ee5\u8003\u8651\u6587\u4ef6\u6620\u5c04                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648004\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wuketidai <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4eba\u5bb6\u5b9e\u65f6\u76f4\u64ad\u624b\u673a\u5f55\u5c4f\u90fd\u53ef\u4ee5\uff0c\u6240\u4ee5\u65e0\u8bba\u5982\u4f55\u90fd\u662f lz \u59ff\u52bf\u4e0d\u5bf9                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648005\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : WispZhan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u6ca1\u7ec6\u7b97\uff0c\u9ed8\u8ba4\u4e0a\u4eec\u90fd\u662f\u5bf9\u7684\u3002<\/p>\n<p>\u8ba9\u6211\u60f3\u5230\u4e00\u4e2a\u7b11\u8bdd\uff1a \u673a\u623f\u5728\u7f8e\u56fd\uff0c\u5ba2\u6237\u5728\u56fd\u5185\uff0c \u5ba2\u6237\u8981\u6c42\u4ece\u56fd\u5185\u8bbf\u95ee\u7f8e\u56fd\u673a\u623f\u7f51\u7edc\u5ef6\u8fdf\u63a7\u5236\u5728 30ms \u4ee5\u5185\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648006\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : weishu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528 jni \u80af\u5b9a\u53ef\u4ee5\u3002\u4f60\u8fd9\u5206\u914d\u8fd9\u4e48\u591a\u4e34\u65f6\u5185\u5b58\uff0cAndroid \u7684 gc \u4e0d\u884c\u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648007\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : CoderGeek <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7f51\u7edc\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648008\" 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>                                                             @rrfeng \u7528 int[] data = new int[width*height];<br \/>bitmap.getPixels(data, 0, width, 0, 0, width, height);\u8f6c\u6210 int[] 800000 \u4ec5\u7528\u4e86 30ms\uff0c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648009\" 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>                                                             @wuketidai \u5bf9\u8def                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648010\" 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>                                                             @May725 \u539f\u59cb\u9700\u6c42\u5c31\u662f\u628a int[] data \u53d1\u9001\u7ed9\u63a5\u6536\u7aef                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648011\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : muzuiget <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u660e\u660e\u74f6\u9888\u5c31\u662f\u5728\u4e8c\u8fdb\u5236\u5e8f\u5217\u5316\uff0csocket \u672c\u8eab\u5c31\u662f\u4e8c\u8fdb\u5236\u6d41\uff0c\u6839\u672c\u5c31\u4e0d\u5173\u5fc3\u4f60\u53d1\u4e86\u4ec0\u4e48\u6570\u636e\u7ed3\u6784\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648012\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : muzuiget <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             bitmap \u5bf9\u8c61\u5e94\u8be5\u76f4\u63a5\u83b7\u53d6\u4e8c\u8fdb\u5236\u6570\u636e\u7684\u65b9\u6cd5\u6216\u8005\u5c5e\u6027\uff0c\u53ef\u80fd\u5c31\u662f\u4e00\u4e2a\u5e26 IO \u4e4b\u7c7b\u7684 Stream \u63a5\u53e3\uff0c\u8ba9\u4f60\u76f4\u63a5 read\/write \u5c31\u5b8c\u4e8b\u4e86\uff0c\u7ed9\u4f60 int[] \u591a\u534a\u5c31\u662f\u8ba9\u4f60\u505a\u56fe\u5f62\u53d8\u6362\u4e4b\u7c7b\uff0c\u4f60\u53ea\u662f\u53d1\u9001\u6570\u636e\uff0c\u5c31\u4e0d\u9700\u8981\u8fd9\u79cd\u64cd\u4f5c\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648013\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : march1993 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7c7b\u4f3c png \u8fd9\u79cd \u4f4e\u9891\u90e8\u5206\u5728\u524d\u9ad8\u9891\u90e8\u5206\u5728\u540e \u8ba9\u63a5\u6536\u7aef\u53ef\u4ee5\u6e10\u8fdb\u5730\u5c55\u793a\u6e05\u6670\u56fe\u4e0d\u884c\u5417\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1648014\" 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>                                                             @muzuiget \u5bf9\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Android \u5982\u4f55\u901a\u8fc7 Sock&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\/99085"}],"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=99085"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/99085\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=99085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=99085"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=99085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}