{"id":13801143,"url":"https://github.com/rpt/gen_tcp_server","last_synced_at":"2025-05-13T11:30:52.398Z","repository":{"id":137137672,"uuid":"4520430","full_name":"rpt/gen_tcp_server","owner":"rpt","description":"Generic TCP Server for Erlang applications","archived":false,"fork":false,"pushed_at":"2015-04-07T13:26:09.000Z","size":321,"stargazers_count":11,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-18T16:57:14.748Z","etag":null,"topics":["erlang","tcp","tcp-server"],"latest_commit_sha":null,"homepage":"","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rpt.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":"2012-06-01T14:22:53.000Z","updated_at":"2023-04-24T01:34:45.000Z","dependencies_parsed_at":"2023-03-14T02:30:39.430Z","dependency_job_id":null,"html_url":"https://github.com/rpt/gen_tcp_server","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpt%2Fgen_tcp_server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpt%2Fgen_tcp_server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpt%2Fgen_tcp_server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpt%2Fgen_tcp_server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rpt","download_url":"https://codeload.github.com/rpt/gen_tcp_server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253932769,"owners_count":21986445,"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":["erlang","tcp","tcp-server"],"created_at":"2024-08-04T00:01:19.988Z","updated_at":"2025-05-13T11:30:51.878Z","avatar_url":"https://github.com/rpt.png","language":"Erlang","readme":"# Generic TCP Server [![Build Status][travis_ci_image]][travis_ci]\n\n**Generic TCP Server** (`gen_tcp_server`) is an Erlang behaviour providing quick and\neasy way to add TCP server functionality to you application. It's implemented as\na supervisor managing TCP connections as it's children.\n\n## How to use it?\n\n * Run `make` to build.\n * Run `make test` to run tests.\n * Add as a dependency to your `rebar.config`:\n\n``` erlang\n{gen_tcp_server, \"\", {git, \"git://github.com/rpt/gen_tcp_server.git\", {tag, \"1.0.1\"}}}\n```\n\n## Callbacks\n\nThe `gen_tcp_server` behaviour specifies three callbacks:\n\n * `handle_accept/1` - called on accepting a new connection\n\n``` erlang\nhandle_accept(Socket :: socket()) -\u003e {ok, State :: term()} | {stop, Reason :: term()}.\n```\n\n * `handle_tcp/3` - for handling incoming TCP data\n\n``` erlang\nhandle_tcp(Socket :: socket(), Data :: binary(), State :: term()) -\u003e {ok, State :: term()} |\n                                                                     {stop, Reason :: term()}.\n```\n\n * `handle_close/3` - called when socket is closed\n\n``` erlang\n-type reason :: normal | {tcp_error, term()} |\n                {handle_accept_error, term()} | {handle_tcp_error, term()}.\n\nhandle_close(Socket :: socket(), Reason :: reason(), State :: term()) -\u003e ok.\n```\n\n## Pool of acceptors\n\nTo use a pool of acceptors use `gen_tcp_server:start_link/3` and specify a `pool` option. For example:\n\n``` erlang\ngen_tcp_server:start_link(handler_module, 1234, [{pool, 10}]).\n```\n\n## Examples\n\nSimple `echo_server` example showing how to use `gen_tcp_server` can be found\n[here][echo_server.erl].\n\n[echo_server.erl]:\nhttps://github.com/rpt/gen_tcp_server/blob/master/examples/echo_server.erl\n[travis_ci]:\nhttp://travis-ci.org/rpt/gen_tcp_server\n[travis_ci_image]:\nhttps://secure.travis-ci.org/rpt/gen_tcp_server.png\n","funding_links":[],"categories":["Networking"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frpt%2Fgen_tcp_server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frpt%2Fgen_tcp_server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frpt%2Fgen_tcp_server/lists"}