{"id":13413637,"url":"https://github.com/two/tspool","last_synced_at":"2026-03-12T03:30:59.538Z","repository":{"id":57486118,"uuid":"154910365","full_name":"two/tspool","owner":"two","description":"tcp server pool","archived":false,"fork":false,"pushed_at":"2018-10-29T01:55:10.000Z","size":6,"stargazers_count":14,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-17T10:44:54.557Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/two.png","metadata":{"files":{"readme":"README.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}},"created_at":"2018-10-27T01:05:03.000Z","updated_at":"2022-09-27T08:57:28.000Z","dependencies_parsed_at":"2022-09-18T18:04:34.516Z","dependency_job_id":null,"html_url":"https://github.com/two/tspool","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/two/tspool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/two%2Ftspool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/two%2Ftspool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/two%2Ftspool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/two%2Ftspool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/two","download_url":"https://codeload.github.com/two/tspool/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/two%2Ftspool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30414258,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T00:40:14.898Z","status":"online","status_checked_at":"2026-03-12T02:00:07.260Z","response_time":114,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-07-30T20:01:45.109Z","updated_at":"2026-03-12T03:30:59.515Z","avatar_url":"https://github.com/two.png","language":"Go","readme":"# tspool\nA TCP Library use worker pool to improve performance and protect your server.\n\n[![Build Status](https://travis-ci.org/two/tspool.svg?branch=master)](https://travis-ci.org/two/tspool)\n[![Code Coverage](https://codecov.io/gh/two/tspool/branch/master/graph/badge.svg)](https://codecov.io/gh/two/tspool)\n[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://opensource.org/licenses/MIT)\n[![GoDoc](https://godoc.org/github.com/two/tspool?status.svg)](https://godoc.org/github.com/two/tspool)\n\n\n## Install\n\n```\ngo get github.com/two/tspool\n```\n\n## Usage\n\nBuild your server with tspool\n### server\n```go\npackage main\n\nimport (\n\t\"github.com/two/tspool\"\n\t\"log\"\n\t\"net\"\n)\n\nfunc main() {\n\twp, err := tspool.DefaultWorkerPool(100, 200)\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\tserver := \u0026tspool.Server{\n\t\tAddr:          \"0.0.0.0:8088\",\n\t\tHandler:       handler,\n\t\tErrHandler:    errHandler,\n\t\tWorkerPool:    wp,\n\t\tRejectHandler: rejectHandler,\n\t}\n\terr = tspool.ListenAndServe(server)\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n}\n\nfunc handler(c net.Conn) {\n\taddr := c.RemoteAddr()\n\tc.Write([]byte(\"hello\"))\n\tc.Close()\n\tlog.Println(addr.String())\n}\n\nfunc errHandler(c net.Conn, err string) {\n\tdefer c.Close()\n\tlog.Fatalln(\"run server error: \" + err)\n}\n\nfunc rejectHandler(c net.Conn, err string) {\n\tdefer c.Close()\n\tlog.Println(\"reject connect error: \" + err)\n}\n```\nBuild your tspool client\n```go\n\npackage main\n\nimport (\n\t\"log\"\n\t\"net\"\n\t\"sync\"\n\t\"time\"\n)\n\nvar wg = new(sync.WaitGroup)\n\nfunc main() {\n\tvar num int = 2000\n\twg.Add(num)\n\tfor i := 0; i \u003c num; i++ {\n\t\tgo conn()\n\t}\n\twg.Wait()\n\tlog.Println(\"done\")\n}\nfunc conn() {\n\tdefer wg.Done()\n\taddr := \"0.0.0.0:8088\"\n\td := net.Dialer{Timeout: 100 * time.Millisecond}\n\tconn, err := d.Dial(\"tcp\", addr)\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\tdefer conn.Close()\n\traddr := conn.LocalAddr()\n\tvar r = make([]byte, 1024)\n\t_, err = conn.Read(r)\n\tif err != nil {\n\t\tlog.Printf(raddr.String() + \" read error: \" + err.Error())\n\t}\n\tlog.Printf(raddr.String() + \" got \" + string(r))\n}\n```\n## Define your own worker pool and worker\n\n## Example\n[example](https://github.com/two/tspool/tree/master/examples)\n","funding_links":[],"categories":["Networking","网络","网络相关库","Relational Databases"],"sub_categories":["Transliteration","音译","Uncategorized","暂未分类","Strings","Advanced Console UIs","暂未分类这些库被放在这里是因为其他类别似乎都不适合。"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwo%2Ftspool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwo%2Ftspool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwo%2Ftspool/lists"}