{"id":13694982,"url":"https://github.com/lvgithub/stick","last_synced_at":"2025-05-03T04:31:23.432Z","repository":{"id":18539852,"uuid":"84559161","full_name":"lvgithub/stick","owner":"lvgithub","description":"solution of \"sticking packets\" for TCP network transmission","archived":false,"fork":false,"pushed_at":"2024-06-12T23:20:00.000Z","size":4820,"stargazers_count":296,"open_issues_count":0,"forks_count":52,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-04-25T06:03:42.734Z","etag":null,"topics":["bytes","net","node","nodejs","package","socket","stick","tcp"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lvgithub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-10T12:45:42.000Z","updated_at":"2024-11-26T14:33:12.000Z","dependencies_parsed_at":"2023-01-13T19:53:10.864Z","dependency_job_id":"1466a9c7-8101-4a48-a873-7337bd571bad","html_url":"https://github.com/lvgithub/stick","commit_stats":{"total_commits":144,"total_committers":6,"mean_commits":24.0,"dds":"0.16666666666666663","last_synced_commit":"75aca5081bc2794080f200930972c995513d9973"},"previous_names":["lvgithub/stickpackage"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lvgithub%2Fstick","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lvgithub%2Fstick/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lvgithub%2Fstick/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lvgithub%2Fstick/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lvgithub","download_url":"https://codeload.github.com/lvgithub/stick/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252144560,"owners_count":21701434,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bytes","net","node","nodejs","package","socket","stick","tcp"],"created_at":"2024-08-02T17:01:54.744Z","updated_at":"2025-05-03T04:31:18.424Z","avatar_url":"https://github.com/lvgithub.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\n\u003cdiv align=\"left\"\u003e\n  \n![issues](https://img.shields.io/github/issues/lvgithub/stick)\n![forks](https://img.shields.io/github/forks/lvgithub/stick)\n![stars](https://img.shields.io/github/stars/lvgithub/stick)\n![linces](https://img.shields.io/github/license/lvgithub/stick)\n![npm](http://img.shields.io/npm/v/@lvgithub/stick.svg?style=flat-square)\n![david](https://img.shields.io/david/lvgithub/stick?style=flat-square)\n![downloads](https://img.shields.io/npm/dm/@lvgithub/stick.svg?style=flat-square)\n\n\u003c/div\u003e\n\n\n\n# 🌈 Introduction\n\n我们使用 TCP 通信的时候，由于TCP是面向流的，因此需要对流进行解析。也就是所谓的拆包，把流解析为一段段我们所需要的数据。本方案为 Node.Js 实现的一个处理方案。\n\n对要发送的数据按协议编码，把数据 `data` 分为 `header` +`body `两部分，header 默认固定长度（_2 byte_），`header`描述的是 `body` 数据的长度。由于`header`定长，因此可以通过`header`，解析出 `body` 的内容。\n\n默认 `header` 我们使用 `2 Byte` 的存储空间，即`Int16`最大表示的 `body` 长度为 `32767`,也就是`16M`。\n\n![Schematic](https://github.com/lvgithub/stick/blob/master/assets/README/schematic.png)\n\n如上图，我们看先取出数据流的前两位，读取到内容 `0x00, 0x02`转化为整数的长度是 2，再读取出`body`第3、4位 `0x61, 0x62`。\n\n## Links\n\n🌈 [Install](https://www.npmjs.com/package/@lvgithub/stick)\n\n👀 [Getting Started](https://github.com/lvgithub/stick/blob/master/docs/GettingStarted.md)\n\n😊 [API Reference](https://github.com/lvgithub/stick/blob/master/docs/API.md)\n\n😸 [Examples](https://github.com/lvgithub/stick/blob/master/examples/readme.md)\n\n🌍 [Solve the problem of \"sticking packets\" for TCP network transmission (Classic)](https://topic.alibabacloud.com/a/solve-the-problem-font-colorredoffont-quotsticking-font-colorredpacketsfontquot-for-tcp-network-transmission-classic_8_8_31915399.html)\n\n## Other Language\n\n现实场景中客户端是其他语言编写的比如C语言运行在单片机上，这时候大家可以基原理图自行打包，规则所示：\n\n```shell\ndata = header(body.length) + body\n```\n\n## [License](http://opensource.org/licenses/MIT)\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flvgithub%2Fstick","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flvgithub%2Fstick","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flvgithub%2Fstick/lists"}