{"id":15470445,"url":"https://github.com/lfex/tcp-client","last_synced_at":"2026-01-20T04:01:53.311Z","repository":{"id":62430359,"uuid":"318976623","full_name":"lfex/tcp-client","owner":"lfex","description":"A simple LFE TCP client connection manager","archived":false,"fork":false,"pushed_at":"2021-06-27T07:36:42.000Z","size":129,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"release/0.2.x","last_synced_at":"2025-09-24T19:57:46.965Z","etag":null,"topics":["beam","connection-manager","erlang","lfe","tcp","tcp-client"],"latest_commit_sha":null,"homepage":"","language":"LFE","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/lfex.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":"2020-12-06T07:29:35.000Z","updated_at":"2022-12-08T15:58:40.000Z","dependencies_parsed_at":"2022-11-01T20:30:58.773Z","dependency_job_id":null,"html_url":"https://github.com/lfex/tcp-client","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/lfex/tcp-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfex%2Ftcp-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfex%2Ftcp-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfex%2Ftcp-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfex%2Ftcp-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lfex","download_url":"https://codeload.github.com/lfex/tcp-client/tar.gz/refs/heads/release/0.2.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfex%2Ftcp-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28595317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T02:08:49.799Z","status":"ssl_error","status_checked_at":"2026-01-20T02:08:44.148Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["beam","connection-manager","erlang","lfe","tcp","tcp-client"],"created_at":"2024-10-02T02:04:43.121Z","updated_at":"2026-01-20T04:01:53.297Z","avatar_url":"https://github.com/lfex.png","language":"LFE","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tcp-client\n\n*A simple LFE TCP client connection manager*\n\n[![Build Status][gh-actions-badge]][gh-actions]\n[![LFE Versions][lfe-badge]][lfe]\n[![Erlang Versions][erlang-badge]][versions]\n[![Tag][github-tag-badge]][github-tag]\n\n[![Project Logo][logo]][logo-large]\n\n## About\n\nThis library provides a simple TCP client for use in non-critical BEAM\napplications such as command line tools and REPLs. That being said, it _is_\nintended to be used from OTP release apps (e.g., making use of configuration\ndata in `./config/sys.config`).\n\nExponential backoff for an unavailable TCP server is provided via Fred's\n[Erlang backoff library](https://github.com/ferd/backoff).\n\n## Configuration\n\nUpdate your application's `sys.config` to include the following:\n\n``` erlang\n[\n %% any other confit entries ...\n {'tcp-client', [\n     {server, [\n         %% where to connect the client\n         {host, \"localhost\"},\n         {port, 7099},\n         {options, [\n             %% gen_tcp options\n             {tcp, [binary, {active, true}, {packet, 0}]},\n             %% The M/F responseible for parsing the packet; Func is arity 2,\n             %% taking the packet data as the first argument and a tuple of\n             %% the reporter {Mod, Func} as the second argument. This M/F is\n             %% called by `connect` when a TCP packet is received.\n             {parser, {Mod, Func}},\n             %% It is up to the parser to call this next M/F, but the reporter\n             %% tuple is what gets passed to the paser M/F.\n             {reporter, {Mod, Func}},\n             %% Exponential backoff support with initial and max values\n             {'init-backoff', 500}, % in ms\n             {'max-backoff', 60000} % in ms\n         ]}\n     ]}\n ]}\n].\n```\n\nYou will need to update the M/Fs for both the paser and the reporter.\n\n## Usage\n\nStart up the connection manager:\n\n``` lisp\nlfe\u003e (application:start 'tcp-client)\n```\n\nSend a message that will wait for a response (\"call\"):\n\n``` lisp\nlfe\u003e (tcp-client:call-msg data)\n```\n\nSend a message that will return immediately (\"cast\"):\n\n``` lisp\nlfe\u003e (tcp-client:cast-msg data)\n```\n\nThe [undertone project](https://github.com/lfex/undertone) uses this library\nwith the following parser and reporter definitions:\n\n``` lisp\n(defun parse-response\n  ((packet `#(,reporter-mod ,reporter-func))\n   (let* ((raw-msgs (split-xt-packet packet))\n          (msgs (maybe-one-msg raw-msgs)))\n     (list-comp\n       ((\u003c- x raw-msgs))\n       (apply reporter-mod reporter-func `(,x)))\n     (log-debug \"Parsed packet: ~p\" `(,msgs))\n     msgs)))\n\n(defun report (data)\n  (log-debug \"Got data from TCP server: ~p\" `(,data)))\n\n(defun rcv-delim () #b(0))\n\n(defun split-xt-packet (packet)\n  (list-comp\n    ((\u003c- x (when (=/= x #b()))\n         (binary:split packet (rcv-delim) '(global))))\n    (xt.lang:-\u003elfe x)))\n\n(defun maybe-one-msg\n  ((`(,msg . ()))\n    msg)\n   ((msgs)\n    msgs))\n```\n\n## Licence\n\nCopyright © 2015, Carlos Andres Bolaños\n\nCopyright © 2019, Andrea Leopardi\n\nCopyright © 2020, Duncan McGreggor\n\n\n[//]: ---Named-Links---\n\n[logo]: priv/images/logo.png\n[logo-large]: priv/images/logo.svg\n[github]: https://github.com/lfex/tcp-client\n[gh-actions-badge]: https://github.com/lfex/tcp-client/workflows/ci%2Fcd/badge.svg\n[gh-actions]: https://github.com/lfex/tcp-client/actions\n[lfe]: https://github.com/rvirding/lfe\n[lfe-badge]: https://img.shields.io/badge/lfe-2.0-blue.svg\n[erlang-badge]: https://img.shields.io/badge/erlang-21%20to%2023-blue.svg\n[versions]: https://github.com/lfex/tcp-client/blob/master/.github/workflows/cicd.yml\n[github-tag]: https://github.com/lfex/tcp-client/tags\n[github-tag-badge]: https://img.shields.io/github/tag/lfex/tcp-client.svg\n[github-downloads]: https://img.shields.io/github/downloads/lfex/tcp-client/total.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfex%2Ftcp-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flfex%2Ftcp-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfex%2Ftcp-client/lists"}