{"id":2746,"date":"2019-01-22T20:00:47","date_gmt":"2019-01-22T12:00:47","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=2746"},"modified":"2019-01-22T20:00:47","modified_gmt":"2019-01-22T12:00:47","slug":"%e4%b8%80%e4%b8%aa%e7%bb%84%e4%bb%b6%e5%8c%96%e3%80%81%e9%ab%98%e6%89%a9%e5%b1%95%e6%80%a7%e3%80%81%e9%ab%98%e6%80%a7%e8%83%bd%e7%9a%84%e5%bc%80%e6%ba%90%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%bd%91%e7%bb%9c","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/2746","title":{"rendered":"\u4e00\u4e2a\u7ec4\u4ef6\u5316\u3001\u9ad8\u6269\u5c55\u6027\u3001\u9ad8\u6027\u80fd\u7684\u5f00\u6e90\u670d\u52a1\u5668\u7f51\u7edc\u5e93cellnet"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/master\/doc\/logo.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/github.com\/davyxu\/cellnet\/raw\/master\/doc\/logo.png\" alt=\"cellnetlogo\" \/><\/a><\/p>\n<p><a href=\"https:\/\/travis-ci.org\/davyxu\/cellnet\" rel=\"nofollow\"><img decoding=\"async\" src=\"https:\/\/camo.githubusercontent.com\/f1c400c24f0336e4c099c5d29008684d3b0f7197\/68747470733a2f2f7472617669732d63692e6f72672f6461767978752f63656c6c6e65742e7376673f6272616e63683d6d6173746572\" alt=\"Build Status\" data-canonical-src=\"https:\/\/travis-ci.org\/davyxu\/cellnet.svg?branch=master\" \/><\/a>\u00a0<a href=\"https:\/\/goreportcard.com\/report\/github.com\/davyxu\/cellnet\" rel=\"nofollow\"><img decoding=\"async\" src=\"https:\/\/camo.githubusercontent.com\/811b14f7ca1f606cdfebf6c5baaf16cfa358f2a4\/68747470733a2f2f676f7265706f7274636172642e636f6d2f62616467652f6769746875622e636f6d2f6461767978752f63656c6c6e6574\" alt=\"Go Report Card\" data-canonical-src=\"https:\/\/goreportcard.com\/badge\/github.com\/davyxu\/cellnet\" \/><\/a>\u00a0<a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/master\/LICENSE\"><img decoding=\"async\" src=\"https:\/\/camo.githubusercontent.com\/890acbdcb87868b382af9a4b1fac507b9659d9bf\/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667\" alt=\"MIT licensed\" data-canonical-src=\"https:\/\/img.shields.io\/badge\/license-MIT-blue.svg\" \/><\/a>\u00a0<a href=\"https:\/\/godoc.org\/github.com\/davyxu\/cellnet\" rel=\"nofollow\"><img decoding=\"async\" src=\"https:\/\/camo.githubusercontent.com\/a835ad01e4ea598ec5f78b70049ffb0621cf8448\/68747470733a2f2f676f646f632e6f72672f6769746875622e636f6d2f6461767978752f63656c6c6e65743f7374617475732e737667\" alt=\"GoDoc\" data-canonical-src=\"https:\/\/godoc.org\/github.com\/davyxu\/cellnet?status.svg\" \/><\/a><\/p>\n<p>cellnet\u662f\u4e00\u4e2a\u7ec4\u4ef6\u5316\u3001\u9ad8\u6269\u5c55\u6027\u3001\u9ad8\u6027\u80fd\u7684\u5f00\u6e90\u670d\u52a1\u5668\u7f51\u7edc\u5e93<\/p>\n<h1><a id=\"user-content-\u4f7f\u7528\u9886\u57df\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E4%BD%BF%E7%94%A8%E9%A2%86%E5%9F%9F\" aria-hidden=\"true\"><\/a>\u4f7f\u7528\u9886\u57df<\/h1>\n<p>cellnet\u7ecf\u8fc7\u591a\u4e2a\u7248\u672c\u7684\u8fed\u4ee3\uff0c\u65e0\u8bba\u662f\u4f5c\u4e3a\u521d\u5b66\u8005\u5b66\u4e60\u7684\u8303\u4f8b\uff0c\u8fd8\u662f\u4f5c\u4e3a\u79c1\u7528\u3001\u5546\u7528\u9879\u76ee\u7684\u57fa\u7840\u6784\u5efa\u4e43\u81f3\u6838\u5fc3\u6280\u672f\u5c42\u5df2\u7ecf\u5728\u4e1a\u5185\u5e7f\u53d7\u4e86\u89e3\u53ca\u4f7f\u7528\u3002<\/p>\n<p>\u4e3b\u8981\u4f7f\u7528\u9886\u57df\uff1a<\/p>\n<ul>\n<li>\u6e38\u620f\u670d\u52a1\u5668\n<p>\u65b9\u4fbf\u5b9a\u5236\u79c1\u6709\u534f\u8bae\uff0c\u5feb\u901f\u6784\u5efa\u903b\u8f91\u670d\u52a1\u5668\u3001\u7f51\u5173\u670d\u52a1\u5668\u3001\u670d\u52a1\u5668\u95f4\u4e92\u8054\u4e92\u901a\u3001\u5bf9\u63a5\u7b2c\u4e09\u65b9SDK\u3001\u8f6c\u6362\u7f16\u7801\u534f\u8bae\u7b49<\/li>\n<li>ARM\u8bbe\u5907\n<p>\u8bbe\u5907\u95f4\u7f51\u7edc\u901a\u8baf<\/li>\n<li>\u8bc1\u5238\u8f6f\u4ef6\n<p>\u5185\u90e8RPC<\/li>\n<\/ul>\n<h1><a id=\"user-content-\u7279\u6027-features\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E7%89%B9%E6%80%A7-features\" aria-hidden=\"true\"><\/a>\u7279\u6027 (Features)<\/h1>\n<h2><a id=\"user-content-\u4f20\u8f93\u534f\u8bae\u652f\u6301\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E4%BC%A0%E8%BE%93%E5%8D%8F%E8%AE%AE%E6%94%AF%E6%8C%81\" aria-hidden=\"true\"><\/a>\u4f20\u8f93\u534f\u8bae\u652f\u6301<\/h2>\n<ul>\n<li>TCP\n<p>TCP\u8fde\u63a5\u5668\u7684\u91cd\u8fde\uff0c\u4fa6\u542c\u5668\u7684\u4f18\u96c5\u91cd\u542f\u3002<\/li>\n<li>UDP\n<p>\u7eafUDP\u88f8\u5305\u6536\u53d1<\/li>\n<li>HTTP(\u6d4b\u8bd5\u4e2d)\n<p>\u4fa6\u542c\u5668\u7684\u4f18\u96c5\u91cd\u542f, \u652f\u6301json\u53caform\u7684\u6536\u53d1\u53ca\u5c01\u88c5\u3002\u7f16\u5199\u6e38\u620f\u670d\u52a1\u5668\u65f6\uff0c\u4e0d\u518d\u9700\u8981\u4f7f\u7528\u7b2c\u4e09\u65b9HTTP\u670d\u52a1\u5668\u5bf9\u63a5SDK\u3002<\/li>\n<li>WebSocket\n<p>\u91c7\u7528(github.com\/gorilla\/websocket)\u5b9e\u73b0<\/li>\n<\/ul>\n<h2><a id=\"user-content-\u7f16\u7801codec\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E7%BC%96%E7%A0%81codec\" aria-hidden=\"true\"><\/a>\u7f16\u7801(Codec)<\/h2>\n<ul>\n<li>cellnet\u5185\u5efa\u652f\u6301\u4ee5\u4e0b\u6570\u636e\u7f16\u7801:\n<ul>\n<li>Google Protobuf (<a href=\"https:\/\/github.com\/google\/protobuf\">https:\/\/github.com\/google\/protobuf<\/a>)<\/li>\n<li>json \u9002\u5408\u4e0e\u7b2c\u4e09\u65b9\u670d\u52a1\u5668\u901a\u4fe1<\/li>\n<li>\u4e8c\u8fdb\u5236\u534f\u8bae(<a href=\"https:\/\/github.com\/davyxu\/goobjfmt\">https:\/\/github.com\/davyxu\/goobjfmt<\/a>)\n<p>\u5185\u5b58\u6d41\u76f4\u63a5\u5e8f\u5217\u5316, \u9002\u7528\u4e8e\u670d\u52a1\u5668\u5185\u7f51\u4f20\u8f93<\/li>\n<li>ProtoPlus(<a href=\"https:\/\/github.com\/davyxu\/protoplus\">https:\/\/github.com\/davyxu\/protoplus<\/a>)\n<p>\u589e\u52a0\u5e76\u4f18\u5316\u8fc7\u7684Protobuf\u7684\u7f16\u7801\u683c\u5f0f<\/li>\n<\/ul>\n<p>\u53ef\u4ee5\u901a\u8fc7codec\u5305\u81ea\u884c\u6dfb\u52a0\u65b0\u7684\u7f16\u7801\u683c\u5f0f<\/li>\n<li>\u652f\u6301\u6df7\u5408\u7f16\u7801\u6536\u53d1\n<p>\u65e0\u9700\u6539\u52a8\u4ee3\u7801\uff0c\u53ea\u9700\u8c03\u6574\u6d88\u606f\u6ce8\u518c\u65b9\u5f0f\uff0c\u5373\u53ef\u8fbe\u6210\u8fd0\u884c\u671f\u540c\u65f6\u6536\u53d1\u4e0d\u540c\u7f16\u7801\u7684\u5c01\u5305<\/p>\n<ul>\n<li>\u4e0eUnity3D+Lua\u4f7f\u7528sproto\u901a\u4fe1<\/li>\n<li>\u4e0e\u5176\u4ed6\u8bed\u8a00\u7f16\u5199\u7684\u670d\u52a1\u5668\u4f7f\u7528protobuf<\/li>\n<li>\u4e0eweb\u670d\u52a1\u5668\u4f7f\u7528json\u901a\u4fe1<\/li>\n<\/ul>\n<p>\u4f18\u70b9\uff1a<\/p>\n<ul>\n<li>\u4eab\u53d7\u4e0d\u540c\u901a\u4fe1\u534f\u8bae\u683c\u5f0f\u7684\u4f18\u70b9\uff0c\u907f\u514d\u7f3a\u70b9\u3002\u5982Protobuf\u9002\u5408\u670d\u52a1\u5668\u95f4\u7684\u4f20\u8f93\uff0c\u5c01\u5305\u5c0f\uff0c\u9002\u5e94\u9762\u5e7f\u3002<\/li>\n<li>\u79c1\u6709\u7684\u4e8c\u8fdb\u5236\u534f\u8bae\u65b9\u4fbf\u52a0\u5bc6\u548c\u5ba2\u6237\u7aef\u5904\u7406\uff0c\u4f4eGC\u548c\u5b9e\u73b0\u590d\u6742\u5ea6\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2><a id=\"user-content-\u961f\u5217\u5b9e\u73b0\u5404\u79cd\u5355\u7ebf\u7a0b\u591a\u7ebf\u7a0b\u5f02\u6b65\u540c\u6b65\u4e1a\u52a1\u5904\u7406\u6a21\u578b\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E9%98%9F%E5%88%97%E5%AE%9E%E7%8E%B0%E5%90%84%E7%A7%8D%E5%8D%95%E7%BA%BF%E7%A8%8B%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%BC%82%E6%AD%A5%E5%90%8C%E6%AD%A5%E4%B8%9A%E5%8A%A1%E5%A4%84%E7%90%86%E6%A8%A1%E5%9E%8B\" aria-hidden=\"true\"><\/a>\u961f\u5217\u5b9e\u73b0\u5404\u79cd\u5355\u7ebf\u7a0b\/\u591a\u7ebf\u7a0b\uff0c\u5f02\u6b65\/\u540c\u6b65\u4e1a\u52a1\u5904\u7406\u6a21\u578b<\/h2>\n<p>\u4f7f\u7528\u961f\u5217\u6d88\u606f\u5904\u7406\u7ed3\u6784\uff0c\u65b9\u4fbf\u5b9e\u73b0\u4ee5\u4e0b\u6548\u679c\uff1a<\/p>\n<ul>\n<li>\u5355\u7ebf\u7a0b\u5f02\u6b65\u903b\u8f91\uff0c\u9002\u7528\u4e8eMMORPG\u590d\u6742\u4ea4\u4e92\uff0c\u514d\u52a0\u9501\u5904\u7406\u5171\u4eab\u6570\u636e\u3002<\/li>\n<li>\u591a\u7ebf\u7a0b\u540c\u6b65\u903b\u8f91\uff0c\u9002\u7528\u4e8e\u673a\u5668\u4eba\u903b\u8f91\uff0c\u6bcf\u4e2a\u673a\u5668\u4eba\u4f7f\u7528\u72ec\u7acb\u7684goroutine\u6536\u53d1\u5904\u7406\uff0c\u673a\u5668\u4eba\u95f4\u4e92\u4e0d\u5e72\u6270\u3002<\/li>\n<li>\u591a\u7ebf\u7a0b\u5e76\u53d1\u903b\u8f91\uff0c\u9002\u7528\u4e8e\u7f51\u5173\uff0c\u6d88\u606f\u8f6c\u53d1\uff0cHTTP\u670d\u52a1\u5668\uff0c\u6bcf\u6761\u6d88\u606f\u5904\u7406\u90fd\u4f1a\u5728\u5b8c\u5168\u5e76\u53d1\u4e0b\u3002<\/li>\n<\/ul>\n<h2><a id=\"user-content-\u8fdc\u7a0b\u8fc7\u7a0b\u8c03\u7528rpc\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E8%BF%9C%E7%A8%8B%E8%BF%87%E7%A8%8B%E8%B0%83%E7%94%A8rpc\" aria-hidden=\"true\"><\/a>\u8fdc\u7a0b\u8fc7\u7a0b\u8c03\u7528\uff08RPC\uff09<\/h2>\n<ul>\n<li>\u652f\u6301\u540c\u6b65RPC\uff0c\u9002\u7528\u4e8e\u540e\u53f0\u670d\u52a1\u5668\u5411\u5176\u4ed6\u670d\u52a1\u5668\u8bf7\u6c42\u6570\u636e\u540e\u518d\u987a\u5904\u7406\u4e8b\u52a1\u3002<\/li>\n<li>\u652f\u6301\u5f02\u6b65RPC\uff0c\u9002\u7528\u4e8e\u5355\u7ebf\u7a0b\u670d\u52a1\u5668\u903b\u8f91\u3002<\/li>\n<\/ul>\n<h2><a id=\"user-content-\u6d88\u606f\u65e5\u5fd7\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E6%B6%88%E6%81%AF%E6%97%A5%E5%BF%97\" aria-hidden=\"true\"><\/a>\u6d88\u606f\u65e5\u5fd7<\/h2>\n<ul>\n<li>\u53ef\u4ee5\u65b9\u4fbf\u7684\u901a\u8fc7\u65e5\u5fd7\u67e5\u770b\u6536\u53d1\u6d88\u606f\u7684\u6bcf\u4e00\u4e2a\u5b57\u6bb5\u6d88\u606f<\/li>\n<\/ul>\n<p><a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/master\/doc\/chatlogger.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/github.com\/davyxu\/cellnet\/raw\/master\/doc\/chatlogger.png\" alt=\"cellnetlogo\" \/><\/a><\/p>\n<h1><a id=\"user-content-\u83b7\u53d6\u7f16\u8bd1\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E8%8E%B7%E5%8F%96%E7%BC%96%E8%AF%91\" aria-hidden=\"true\"><\/a>\u83b7\u53d6+\u7f16\u8bd1<\/h1>\n<p>\u7f16\u8bd1\u548c\u4f7f\u7528cellnet\uff0c\u8bf7\u4e0b\u8f7dGo1.10\u4ee5\u4e0a\u7248\u672c<\/p>\n<pre><code>  go get -v github.com\/davyxu\/cellnet\r\n\r\n  go get -v github.com\/davyxu\/golog\r\n\r\n  go get -v github.com\/davyxu\/goobjfmt\r\n\r\n  go get -v github.com\/davyxu\/protoplus\r\n<\/code><\/pre>\n<h1><a id=\"user-content-\u7b2c\u4e09\u65b9\u5e93\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%93\" aria-hidden=\"true\"><\/a>\u7b2c\u4e09\u65b9\u5e93<\/h1>\n<p>cellnet \u4f7f\u7528Protobuf\u65f6\uff0c\u9700\u8981\u4f7f\u7528\u9644\u5e26\u7684pb\u63d2\u4ef6\u751f\u6210\u4e00\u4e2a\u7ed1\u5b9a\u4ee3\u7801\uff0c\u4e0b\u9762\u7684\u94fe\u63a5\u53ef\u4ee5\u5904\u7406\u8fd9\u4e2a\u95ee\u9898\u00a0<a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/master\/doc\/pbcodec.md\">Google Protobuf \u7f16\u7801\u5b89\u88c5<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/gorilla\/websocket\">WebSocket\u5b9e\u73b0<\/a><\/p>\n<h1><a id=\"user-content-\u67b6\u6784\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E6%9E%B6%E6%9E%84\" aria-hidden=\"true\"><\/a>\u67b6\u6784<\/h1>\n<p>cellnet\u67b6\u6784\u5c42\u6b21\u7531\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/master\/doc\/architecture.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/github.com\/davyxu\/cellnet\/raw\/master\/doc\/architecture.png\" alt=\"architecture\" \/><\/a><\/p>\n<p>cellnet\u5bf9Processor\u548cPeer\u8fdb\u884c\u9ad8\u5ea6\u62bd\u8c61\uff0c\u7528\u6237\u53ef\u4ee5\u4ece\u8fd9\u4e24\u4e2a\u5c42\u9762\u6a2a\u5411\u6269\u5c55\u4ee5\u6ee1\u8db3\u4e0d\u540c\u7684\u7f51\u7edc\u5c01\u88c5\u9700\u6c42<\/p>\n<p>\u7ea2\u8272\u6846\u5185\u7684\u90e8\u5206\u4e3acellnet\u5b9e\u73b0\u90e8\u5206<\/p>\n<h1><a id=\"user-content-\u6d88\u606f\u5904\u7406\u6d41\u7a0b\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E6%B6%88%E6%81%AF%E5%A4%84%E7%90%86%E6%B5%81%E7%A8%8B\" aria-hidden=\"true\"><\/a>\u6d88\u606f\u5904\u7406\u6d41\u7a0b<\/h1>\n<p>cellnet\u7684\u6d88\u606f\u6536\u53d1\u5904\u7406\u6d41\u7a0b\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/master\/doc\/procflow.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/github.com\/davyxu\/cellnet\/raw\/master\/doc\/procflow.png\" alt=\"procflow\" \/><\/a><\/p>\n<p>\u672c\u56fe\u5bf9\u5e94\u7684\u63a5\u53e3\u4e3acellnet\/processor.go<\/p>\n<h1><a id=\"user-content-\u6837\u4f8b\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E6%A0%B7%E4%BE%8B\" aria-hidden=\"true\"><\/a>\u6837\u4f8b<\/h1>\n<div class=\"highlight highlight-source-go\">\n<pre><span class=\"pl-k\">const<\/span> peerAddress = <span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>127.0.0.1:17701<span class=\"pl-pds\">\"<\/span><\/span>\r\n\r\n<span class=\"pl-c\">\/\/ \u670d\u52a1\u5668\u903b\u8f91<\/span>\r\n<span class=\"pl-k\">func<\/span> <span class=\"pl-en\">server<\/span>() {\r\n\r\n    <span class=\"pl-c\">\/\/ \u521b\u5efa\u670d\u52a1\u5668\u7684\u4e8b\u4ef6\u961f\u5217\uff0c\u6240\u6709\u7684\u6d88\u606f\uff0c\u4e8b\u4ef6\u90fd\u4f1a\u88ab\u6295\u5165\u8fd9\u4e2a\u961f\u5217\u5904\u7406<\/span>\r\n\t<span class=\"pl-smi\">queue<\/span> <span class=\"pl-k\">:=<\/span> cellnet.<span class=\"pl-c1\">NewEventQueue<\/span>()\r\n\r\n    <span class=\"pl-c\">\/\/ \u521b\u5efa\u4e00\u4e2a\u670d\u52a1\u5668\u7684\u63a5\u53d7\u5668(Acceptor)\uff0c\u63a5\u53d7\u5ba2\u6237\u7aef\u7684\u8fde\u63a5<\/span>\r\n\t<span class=\"pl-smi\">peerIns<\/span> <span class=\"pl-k\">:=<\/span> peer.<span class=\"pl-c1\">NewGenericPeer<\/span>(<span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>tcp.Acceptor<span class=\"pl-pds\">\"<\/span><\/span>, <span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>server<span class=\"pl-pds\">\"<\/span><\/span>, peerAddress, queue)\r\n\r\n    <span class=\"pl-c\">\/\/ \u5c06\u63a5\u53d7\u5668Peer\u4e0etcp.ltv\u7684\u5904\u7406\u5668\u7ed1\u5b9a\uff0c\u5e76\u8bbe\u7f6e\u4e8b\u4ef6\u5904\u7406\u56de\u8c03<\/span>\r\n    <span class=\"pl-c\">\/\/ tcp.ltv\u5904\u7406\u5668\u8d1f\u8d23\u5904\u7406\u6d88\u606f\u6536\u53d1\uff0c\u4f7f\u7528\u79c1\u6709\u7684\u5c01\u5305\u683c\u5f0f\u4ee5\u53ca\u65e5\u5fd7\uff0cRPC\u7b49\u5904\u7406<\/span>\r\n\tproc.<span class=\"pl-c1\">BindProcessorHandler<\/span>(peerIns, <span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>tcp.ltv<span class=\"pl-pds\">\"<\/span><\/span>, <span class=\"pl-c1\">func<\/span>(ev cellnet.<span class=\"pl-smi\">Event<\/span>) {\r\n\r\n        <span class=\"pl-c\">\/\/ \u5904\u7406Peer\u6536\u5230\u7684\u5404\u79cd\u4e8b\u4ef6<\/span>\r\n\t\t<span class=\"pl-k\">switch<\/span> <span class=\"pl-smi\">msg<\/span> <span class=\"pl-k\">:=<\/span> ev.<span class=\"pl-c1\">Message<\/span>().(<span class=\"pl-k\">type<\/span>) {\r\n\t\t<span class=\"pl-k\">case<\/span> *cellnet.<span class=\"pl-smi\">SessionAccepted<\/span>: <span class=\"pl-c\">\/\/ \u63a5\u53d7\u4e00\u4e2a\u8fde\u63a5<\/span>\r\n\t\t\tfmt.<span class=\"pl-c1\">Println<\/span>(<span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>server accepted<span class=\"pl-pds\">\"<\/span><\/span>)\r\n\t\t<span class=\"pl-k\">case<\/span> *TestEchoACK: <span class=\"pl-c\">\/\/ \u6536\u5230\u8fde\u63a5\u53d1\u9001\u7684\u6d88\u606f<\/span>\r\n\r\n\t\t\tfmt.<span class=\"pl-c1\">Printf<\/span>(<span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>server recv <span class=\"pl-c1\">%+v<\/span><span class=\"pl-cce\">\\n<\/span><span class=\"pl-pds\">\"<\/span><\/span>, msg)\r\n\r\n            <span class=\"pl-c\">\/\/ \u53d1\u9001\u56de\u5e94\u6d88\u606f<\/span>\r\n\t\t\tev.<span class=\"pl-c1\">Session<\/span>().<span class=\"pl-c1\">Send<\/span>(&amp;TestEchoACK{\r\n\t\t\t\tMsg:   msg.<span class=\"pl-smi\">Msg<\/span>,\r\n\t\t\t\tValue: msg.<span class=\"pl-smi\">Value<\/span>,\r\n\t\t\t})\r\n\r\n\t\t<span class=\"pl-k\">case<\/span> *cellnet.<span class=\"pl-smi\">SessionClosed<\/span>: <span class=\"pl-c\">\/\/ \u4f1a\u8bdd\u8fde\u63a5\u65ad\u5f00<\/span>\r\n\t\t\tfmt.<span class=\"pl-c1\">Println<\/span>(<span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>session closed: <span class=\"pl-pds\">\"<\/span><\/span>, ev.<span class=\"pl-c1\">Session<\/span>().<span class=\"pl-c1\">ID<\/span>())\r\n\t\t}\r\n\r\n\t})\r\n\r\n    <span class=\"pl-c\">\/\/ \u542f\u52a8Peer\uff0c\u670d\u52a1\u5668\u5f00\u59cb\u4fa6\u542c<\/span>\r\n\tpeerIns.<span class=\"pl-c1\">Start<\/span>()\r\n\r\n    <span class=\"pl-c\">\/\/ \u5f00\u542f\u4e8b\u4ef6\u961f\u5217\uff0c\u5f00\u59cb\u5904\u7406\u4e8b\u4ef6\uff0c\u6b64\u51fd\u6570\u4e0d\u963b\u585e<\/span>\r\n\tqueue.<span class=\"pl-c1\">StartLoop<\/span>()\r\n}\r\n\r\n<span class=\"pl-c\">\/\/ \u6a21\u62df\u5ba2\u6237\u7aef\u903b\u8f91<\/span>\r\n<span class=\"pl-k\">func<\/span> <span class=\"pl-en\">client<\/span>() {\r\n\r\n    <span class=\"pl-c\">\/\/ \u4f8b\u5b50\u4e13\u7528\u7684\u5b8c\u6210\u6807\u8bb0<\/span>\r\n\t<span class=\"pl-smi\">done<\/span> <span class=\"pl-k\">:=<\/span> <span class=\"pl-c1\">make<\/span>(<span class=\"pl-k\">chan<\/span> <span class=\"pl-k\">struct<\/span>{})\r\n\r\n    <span class=\"pl-c\">\/\/ \u521b\u5efa\u5ba2\u6237\u7aef\u7684\u4e8b\u4ef6\u5904\u7406\u961f\u5217<\/span>\r\n\t<span class=\"pl-smi\">queue<\/span> <span class=\"pl-k\">:=<\/span> cellnet.<span class=\"pl-c1\">NewEventQueue<\/span>()\r\n\r\n    <span class=\"pl-c\">\/\/ \u521b\u5efa\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u5668<\/span>\r\n\t<span class=\"pl-smi\">peerIns<\/span> <span class=\"pl-k\">:=<\/span> peer.<span class=\"pl-c1\">NewGenericPeer<\/span>(<span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>tcp.Connector<span class=\"pl-pds\">\"<\/span><\/span>, <span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>client<span class=\"pl-pds\">\"<\/span><\/span>, peerAddress, queue)\r\n\r\n    <span class=\"pl-c\">\/\/ \u5c06\u5ba2\u6237\u7aef\u8fde\u63a5\u5668Peer\u4e0etcp.ltv\u5904\u7406\u5668\u7ed1\u5b9a\uff0c\u5e76\u8bbe\u7f6e\u63a5\u6536\u4e8b\u4ef6\u56de\u8c03<\/span>\r\n\tproc.<span class=\"pl-c1\">BindProcessorHandler<\/span>(peerIns, <span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>tcp.ltv<span class=\"pl-pds\">\"<\/span><\/span>, <span class=\"pl-c1\">func<\/span>(ev cellnet.<span class=\"pl-smi\">Event<\/span>) {\r\n\r\n\t\t<span class=\"pl-k\">switch<\/span> <span class=\"pl-smi\">msg<\/span> <span class=\"pl-k\">:=<\/span> ev.<span class=\"pl-c1\">Message<\/span>().(<span class=\"pl-k\">type<\/span>) {\r\n\t\t<span class=\"pl-k\">case<\/span> *cellnet.<span class=\"pl-smi\">SessionConnected<\/span>: <span class=\"pl-c\">\/\/ \u5df2\u7ecf\u8fde\u63a5\u4e0a<\/span>\r\n\t\t\tfmt.<span class=\"pl-c1\">Println<\/span>(<span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>client connected<span class=\"pl-pds\">\"<\/span><\/span>)\r\n\t\t\tev.<span class=\"pl-c1\">Session<\/span>().<span class=\"pl-c1\">Send<\/span>(&amp;TestEchoACK{\r\n\t\t\t\tMsg:   <span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>hello<span class=\"pl-pds\">\"<\/span><\/span>,\r\n\t\t\t\tValue: <span class=\"pl-c1\">1234<\/span>,\r\n\t\t\t})\r\n\t\t<span class=\"pl-k\">case<\/span> *TestEchoACK: <span class=\"pl-c\">\/\/\u6536\u5230\u670d\u52a1\u5668\u53d1\u9001\u7684\u6d88\u606f<\/span>\r\n\r\n\t\t\tfmt.<span class=\"pl-c1\">Printf<\/span>(<span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>client recv <span class=\"pl-c1\">%+v<\/span><span class=\"pl-cce\">\\n<\/span><span class=\"pl-pds\">\"<\/span><\/span>, msg)\r\n\r\n\t\t\t<span class=\"pl-c\">\/\/ \u5b8c\u6210\u64cd\u4f5c<\/span>\r\n\t\t\tdone <span class=\"pl-k\">&lt;-<\/span> <span class=\"pl-k\">struct<\/span>{}{}\r\n\r\n\t\t<span class=\"pl-k\">case<\/span> *cellnet.<span class=\"pl-smi\">SessionClosed<\/span>:\r\n\t\t\tfmt.<span class=\"pl-c1\">Println<\/span>(<span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>client closed<span class=\"pl-pds\">\"<\/span><\/span>)\r\n\t\t}\r\n\t})\r\n\r\n    <span class=\"pl-c\">\/\/ \u5f00\u542f\u5ba2\u6237\u7aefPeer<\/span>\r\n\tpeerIns.<span class=\"pl-c1\">Start<\/span>()\r\n\r\n    <span class=\"pl-c\">\/\/ \u5f00\u542f\u5ba2\u6237\u7aef\u961f\u5217\u5904\u7406<\/span>\r\n\tqueue.<span class=\"pl-c1\">StartLoop<\/span>()\r\n\r\n\t<span class=\"pl-c\">\/\/ \u7b49\u5f85\u5ba2\u6237\u7aef\u6536\u5230\u6d88\u606f<\/span>\r\n\t<span class=\"pl-k\">&lt;-<\/span>done\r\n}\r\n<\/pre>\n<\/div>\n<h1><a id=\"user-content-\u76ee\u5f55\u529f\u80fd\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E7%9B%AE%E5%BD%95%E5%8A%9F%E8%83%BD\" aria-hidden=\"true\"><\/a>\u76ee\u5f55\u529f\u80fd<\/h1>\n<p><a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/master\/doc\/dirstruct.md\">\u76ee\u5f55\u53ca\u529f\u80fd\u4e00\u89c8<\/a><\/p>\n<h1><a id=\"user-content-\u8fd0\u884c\u804a\u5929\u4f8b\u5b50\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E8%BF%90%E8%A1%8C%E8%81%8A%E5%A4%A9%E4%BE%8B%E5%AD%90\" aria-hidden=\"true\"><\/a>\u8fd0\u884c\u804a\u5929\u4f8b\u5b50<\/h1>\n<p><strong>\u786e\u8ba4GOPATH\u8bbe\u7f6e\u6b63\u786e\uff01\uff01<\/strong><\/p>\n<p>\u5047\u8bbe GOPATH\u8bbe\u7f6e\u4e3a\/home\/you\/go<\/p>\n<p>\u90a3\u4e48 cellnet\u7ed3\u6784\u4f4d\u4e8e \/home\/you\/go\/src\/github.com\/davyxu\/cellnet<\/p>\n<h2><a id=\"user-content-\u8fd0\u884c-\u670d\u52a1\u5668\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E8%BF%90%E8%A1%8C-%E6%9C%8D%E5%8A%A1%E5%99%A8\" aria-hidden=\"true\"><\/a>\u8fd0\u884c \u670d\u52a1\u5668<\/h2>\n<div class=\"highlight highlight-source-shell\">\n<pre><span class=\"pl-c1\">cd<\/span> examples\/chat\/server\r\n\r\ngo run main.go<\/pre>\n<\/div>\n<h2><a id=\"user-content-\u8fd0\u884c-\u5ba2\u6237\u7aef\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E8%BF%90%E8%A1%8C-%E5%AE%A2%E6%88%B7%E7%AB%AF\" aria-hidden=\"true\"><\/a>\u8fd0\u884c \u5ba2\u6237\u7aef<\/h2>\n<div class=\"highlight highlight-source-shell\">\n<pre><span class=\"pl-c1\">cd<\/span> examples\/chat\/client\r\n\r\ngo run main.go<\/pre>\n<\/div>\n<p>\u968f\u540e, \u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165hello\u540e\u6253\u56de\u8f66, \u5c31\u53ef\u4ee5\u770b\u5230\u670d\u52a1\u5668\u8fd4\u56de<\/p>\n<pre><code>\r\nsid1 say: hello\r\n\r\n<\/code><\/pre>\n<h1><a id=\"user-content-\u57fa\u672c\u6982\u5ff5\u53ca\u4f7f\u7528\u8bf4\u660e\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5%E5%8F%8A%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E\" aria-hidden=\"true\"><\/a>\u57fa\u672c\u6982\u5ff5\u53ca\u4f7f\u7528\u8bf4\u660e<\/h1>\n<p>\u7406\u89e3\u4e0b\u9762\u94fe\u63a5\u4e2d\u7684\u6982\u5ff5\uff0c\u53ef\u4ee5\u8fc5\u901f\u4f7f\u7528cellnet\u505a\u57fa\u672c\u7684\u7f51\u7edc\u901a\u8baf\u53ca\u6d88\u606f\u5904\u7406<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/master\/doc\/queue.md\">\u961f\u5217<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/master\/doc\/peer.md\">\u7aef(Peer)<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/master\/doc\/procmsg.md\">\u6536\u53d1\u5904\u7406\u6d88\u606f<\/a><\/li>\n<\/ul>\n<h1><a id=\"user-content-\u6269\u5c55\u53ca\u5b9a\u5236\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E6%89%A9%E5%B1%95%E5%8F%8A%E5%AE%9A%E5%88%B6\" aria-hidden=\"true\"><\/a>\u6269\u5c55\u53ca\u5b9a\u5236<\/h1>\n<p>\u82e5cellnet\u5185\u5efa\u7684Peer, Codec\u53caProcessor\u6d41\u7a0b\u4e0d\u80fd\u6ee1\u8db3\u4f60\u7684\u9700\u6c42\uff0c\u53ef\u4ee5\u9605\u8bfb\u4e0b\u9762\u94fe\u63a5\u5185\u5bb9\uff0c\u6dfb\u52a0\u5e76\u6269\u5c55cellnet\u529f\u80fd<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/master\/doc\/customcodec.md\">\u5b9a\u5236\u5c01\u5305\u7f16\u7801(Codec)<\/a>\n<p>\u5c01\u5305\u7f16\u7801\u53ef\u4ee5\u662fJSON\uff0cProtobuf\u7b49<\/li>\n<li><a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/master\/doc\/custompeer.md\">\u5b9a\u5236\u7aef(Peer)<\/a>\n<p>\u65b0\u589eRedis\u8fde\u63a5\u5668\uff0c\u4e0ecellnet\u81ea\u5e26\u7684TCP\/UDP\u7684Peer\u90fd\u4e0d\u540c\u3002<\/li>\n<li><a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/master\/doc\/customproc.md\">\u5b9a\u5236\u5904\u7406\u5668(Processor)<\/a>\n<p>\u9700\u8981\u5728\u6536\u53d1\u5305\u65f6\u6709\u7edf\u4e00\u7684\u5904\u7406\u884c\u4e3a<\/li>\n<\/ul>\n<h1><a id=\"user-content-faq\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#faq\" aria-hidden=\"true\"><\/a>FAQ<\/h1>\n<p><a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/master\/doc\/faq.md\">\u5e38\u89c1\u95ee\u9898\u53ca\u56de\u7b54<\/a><\/p>\n<p>\u8fd9\u91cc\u5e94\u8be5\u6709\u4f60\u60f3\u77e5\u9053\u7684\u7b54\u6848<\/p>\n<h1><a id=\"user-content-\u57fa\u4e8ecellnet\u7684\u6e38\u620f\u670d\u52a1\u5668\u6846\u67b6\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E5%9F%BA%E4%BA%8Ecellnet%E7%9A%84%E6%B8%B8%E6%88%8F%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%A1%86%E6%9E%B6\" aria-hidden=\"true\"><\/a>\u57fa\u4e8ecellnet\u7684\u6e38\u620f\u670d\u52a1\u5668\u6846\u67b6<\/h1>\n<p>cellmesh\u00a0<a href=\"https:\/\/github.com\/davyxu\/cellmesh\">https:\/\/github.com\/davyxu\/cellmesh<\/a><\/p>\n<h1><a id=\"user-content-\u8d21\u732e\u8005\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E8%B4%A1%E7%8C%AE%E8%80%85\" aria-hidden=\"true\"><\/a>\u8d21\u732e\u8005<\/h1>\n<p>\u6309\u8d21\u732e\u65f6\u95f4\u6392\u5e8f\uff0c\u8d8a\u9760\u524d\u8868\u793a\u8d8a\u65b0\u7684\u8d21\u732e<\/p>\n<p>superikw(<a href=\"https:\/\/github.com\/superikw\">https:\/\/github.com\/superikw<\/a>), \u5728v3\u4e2d\u6d4b\u8bd5\u51fa\u4e00\u4e2awebsocket\u63a5\u53e3\u5e76\u53d1\u53d1\u9001\u95ee\u9898\uff0cwss\u652f\u6301\uff0c\u4fee\u590d\u4f1a\u8bdd\u7ba1\u7406\u3002<\/p>\n<p>bruce.hu(<a href=\"https:\/\/github.com\/hxdhero\">https:\/\/github.com\/hxdhero<\/a>), \u5728v3\u4e2d\u6d4b\u8bd5\u51fa\u4e00\u4e2a\u7ade\u6001\u51b2\u7a81\u7684bug<\/p>\n<p>M4tou(<a href=\"https:\/\/github.com\/mutousay\">https:\/\/github.com\/mutousay<\/a>), \u5728v3\u4e2d\u534f\u52a9\u89e3\u51b3RPC\u5f02\u6b65\u8d85\u65f6\u56de\u8c03\u5904\u7406<\/p>\n<p>chuan.li(<a href=\"https:\/\/github.com\/blade-226\">https:\/\/github.com\/blade-226<\/a>), \u5728v3\u4e2d\u63d0\u4f9b\u4e00\u4e2a\u6ca1\u6709\u5728io\u7ebf\u7a0b\u7f16\u7801\u7684bug<\/p>\n<p>Chris Lonng(<a href=\"https:\/\/github.com\/lonnng\">https:\/\/github.com\/lonnng<\/a>), \u5728v3\u4e2d\u63d0\u4f9b\u4e00\u4e2a\u6700\u5927\u5c01\u5305\u7ea6\u675f\u9020\u6210\u670d\u52a1\u5668\u95f4\u8fde\u63a5\u65ad\u5f00\u7684bug<\/p>\n<p>IronsDu(<a href=\"https:\/\/github.com\/IronsDu\">https:\/\/github.com\/IronsDu<\/a>), \u5728v2\u4e2d\u5927\u5e45\u5ea6\u6027\u80fd\u4f18\u5316<\/p>\n<p>viwii(<a href=\"mailto:viwii@sina.cn\">viwii@sina.cn<\/a>), \u5728v2\u4e2d\uff0c\u63d0\u4f9b\u4e00\u4e2a\u53ef\u80fd\u9020\u6210\u6b7b\u9501\u7684bug<\/p>\n<h1><a id=\"user-content-\u7248\u672c\u5386\u53f2\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E7%89%88%E6%9C%AC%E5%8E%86%E5%8F%B2\" aria-hidden=\"true\"><\/a>\u7248\u672c\u5386\u53f2<\/h1>\n<p>2018.5 v4\u7248\u672c\u00a0<a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/v4\/CHANGES.md\">\u8be6\u7ec6\u8bf7\u67e5\u770b<\/a><\/p>\n<p>2017.8 v3\u7248\u672c\u00a0<a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/v3\/CHANGES.md\">\u8be6\u7ec6\u8bf7\u67e5\u770b<\/a><\/p>\n<p>2017.1 v2\u7248\u672c\u00a0<a href=\"https:\/\/github.com\/davyxu\/cellnet\/blob\/v2\/CHANGES.md\">\u8be6\u7ec6\u8bf7\u67e5\u770b<\/a><\/p>\n<p>2015.8 v1\u7248\u672c<\/p>\n<h1><a id=\"user-content-\u5907\u6ce8\" class=\"anchor\" href=\"https:\/\/github.com\/davyxu\/cellnet#%E5%A4%87%E6%B3%A8\" aria-hidden=\"true\"><\/a>\u5907\u6ce8<\/h1>\n<p>\u611f\u89c9\u4e0d\u9519\u8bf7star, \u8c22\u8c22!<\/p>\n<p>\u5f00\u6e90\u8ba8\u8bba\u7fa4: 527430600<\/p>\n<p>\u77e5\u4e4e:\u00a0<a href=\"http:\/\/www.zhihu.com\/people\/sunicdavy\" rel=\"nofollow\">http:\/\/www.zhihu.com\/people\/sunicdavy<\/a><\/p>\n<p>\u63d0\u4ea4bug\u53ca\u7279\u6027:\u00a0<a href=\"https:\/\/github.com\/davyxu\/cellnet\/issues\">https:\/\/github.com\/davyxu\/cellnet\/issues<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0\u00a0\u00a0 cellnet\u662f\u4e00\u4e2a\u7ec4\u4ef6\u5316\u3001\u9ad8\u6269<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[122],"class_list":["post-2746","post","type-post","status-publish","format-standard","hentry","tag-06-godocker"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/2746","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=2746"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/2746\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=2746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=2746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=2746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}