{"id":18449458,"url":"https://github.com/lim-yoona/tcp-server-framework","last_synced_at":"2025-04-16T17:32:57.147Z","repository":{"id":161650277,"uuid":"636171086","full_name":"lim-yoona/TCP-server-framework","owner":"lim-yoona","description":"The TCP server framework is a TCP based lightweight server framework that can help developers quickly build network communication applications, supporting high concurrency.","archived":false,"fork":false,"pushed_at":"2024-02-17T15:03:08.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-16T13:34:34.736Z","etag":null,"topics":["go","golang","golang-application","goroutine-pool","tcp-server"],"latest_commit_sha":null,"homepage":"","language":"Go","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/lim-yoona.png","metadata":{"files":{"readme":"README-CN.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2023-05-04T09:14:01.000Z","updated_at":"2024-02-17T13:26:33.000Z","dependencies_parsed_at":"2023-06-19T06:26:29.671Z","dependency_job_id":null,"html_url":"https://github.com/lim-yoona/TCP-server-framework","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lim-yoona%2FTCP-server-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lim-yoona%2FTCP-server-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lim-yoona%2FTCP-server-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lim-yoona%2FTCP-server-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lim-yoona","download_url":"https://codeload.github.com/lim-yoona/TCP-server-framework/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249117278,"owners_count":21215358,"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":["go","golang","golang-application","goroutine-pool","tcp-server"],"created_at":"2024-11-06T07:20:12.067Z","updated_at":"2025-04-15T17:24:54.923Z","avatar_url":"https://github.com/lim-yoona.png","language":"Go","readme":"# TCP server framework\r\n简体中文 | [English](README.md)\r\n\r\n[![License](https://img.shields.io/github/license/lim-yoona/Golang-Design-Patterns)](LICENSE)\r\n\r\nTCP server framework是一个基于TCP的轻量级服务器框架，支持高并发，用于快速构建网络通信应用。\r\n\r\n## 架构\r\n\r\n[![架构](https://s11.ax1x.com/2024/02/17/pFJZbS1.png)](https://imgse.com/i/pFJZbS1)  \r\n\r\n## 特性\r\n\r\n1. **`TLV` 消息格式**。 客⼾端服务端通讯采⽤TLV协议，实现消息包装器处理TCP字节流  \r\n2. **多路由**。 通过消息标识符实现多路由处理消息，⽀持开发者⾃定义多路由   \r\n3. **协程池**。 采⽤协程池处理业务，将消息负载均衡地分配给协程处理，实现协程的复⽤，避免海量协程调度的开销  \r\n4. **顺序处理**。 将来⾃同⼀TCP连接的消息分配给协程池中的固定协程，实现消息按序处理  \r\n5. **读写分离**。 对于每个连接，采⽤读写分离模型来处理，实现⾼内聚低耦合  \r\n\r\n## 使用\r\n\r\n首先， `clone` 本项目， 使用\r\n```shell\r\ngit clone https://github.com/lim-yoona/TCP-server-framework.git\r\n```\r\n用于 `https` 或\r\n```shell\r\ngit clone git@github.com:lim-yoona/TCP-server-framework.git\r\n```\r\n用于 `ssh`.\r\n\r\n**demo** 文件夹下有一些用例。\r\n\r\n具体来说, 你可以通过继承 **`BaseRouter`** 类并且重写它的方法来自定义路由。\r\n\r\n```go\r\ntype MyRouter struct {\r\n\tseNet.BaseRouter\r\n}\r\n\r\nfunc (this *MyRouter) Handle(request seInterface.IRequest) {\r\n\t···\r\n\terr := request.GetConnection().SendMsg(200, []byte(···))\r\n\t···\r\n}\r\n```\r\n\r\n然后你可以使用 **Server** 的 **`AddRouter`** 方法来注册路由, 第一个参数是 ID, 处理对应 ID 的消息, 第二个参数是你的自定义路由。\r\n\r\n最后, 通过调用 **Server** 的 **`Serve`** 方法来启动服务器。\r\n\r\n```go\r\nfunc main() {\r\n\ts := seNet.NewServer()\r\n\t\r\n\ts.AddRouter(0, \u0026MyRouter{})\r\n\t\r\n\ts.Serve()\r\n}\r\n```\r\n\r\n你也可以通过 **Server** 的 **`SetOnConnStart`** 和 **`SetOnConnStop`** 方法来添加 **hook 函数** ， 就像 [示例](https://github.com/lim-yoona/TCP-server-framework/tree/main/demo/v1.0) 中那样.   \r\n\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flim-yoona%2Ftcp-server-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flim-yoona%2Ftcp-server-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flim-yoona%2Ftcp-server-framework/lists"}