{"id":15514724,"url":"https://github.com/fgasper/p5-net-libwebsockets","last_synced_at":"2025-03-28T19:21:34.813Z","repository":{"id":56834614,"uuid":"378481761","full_name":"FGasper/p5-Net-Libwebsockets","owner":"FGasper","description":"CPAN’s Net::Libwebsockets","archived":false,"fork":false,"pushed_at":"2021-11-14T02:40:50.000Z","size":526,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-02T20:51:08.229Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FGasper.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-19T18:39:51.000Z","updated_at":"2024-11-07T10:17:43.000Z","dependencies_parsed_at":"2022-09-02T03:51:24.092Z","dependency_job_id":null,"html_url":"https://github.com/FGasper/p5-Net-Libwebsockets","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/FGasper%2Fp5-Net-Libwebsockets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FGasper%2Fp5-Net-Libwebsockets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FGasper%2Fp5-Net-Libwebsockets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FGasper%2Fp5-Net-Libwebsockets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FGasper","download_url":"https://codeload.github.com/FGasper/p5-Net-Libwebsockets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246085655,"owners_count":20721213,"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":[],"created_at":"2024-10-02T10:00:25.833Z","updated_at":"2025-03-28T19:21:34.788Z","avatar_url":"https://github.com/FGasper.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nNet::Libwebsockets - [libwebsockets](https://libwebsockets.org) in Perl\n\n# SYNOPSIS\n\nWebSocket with [AnyEvent](https://metacpan.org/pod/AnyEvent)\n([IO::Async](https://metacpan.org/pod/IO%3A%3AAsync) and [Mojolicious](https://metacpan.org/pod/Mojolicious) are supported, too):\n\n    my $cv = AE::cv();\n\n    my $done_p = Net::Libwebsockets::WebSocket::Client::connect(\n        url   =\u003e 'wss://echo.websocket.org',\n        event =\u003e 'AnyEvent',\n        on_ready =\u003e sub ($courier) {\n\n            # $courier ferries messages between the caller and the peer:\n\n            $courier-\u003esend_text( $characters );\n            $courier-\u003esend_binary( $bytes );\n\n            # If a message arrives for a type that has no listener,\n            # a warning is thrown.\n            $courier-\u003eon_text( sub ($characters) { .. } );\n            $courier-\u003eon_binary( sub ($bytes) { .. } );\n        },\n    );\n\n    # This promise finishes when the connection is done.\n    # On successful close it resolves with [ $code, $reason ];\n    # see the documentation for failure-case behavior.\n    #\n    $done_p-\u003ethen(\n        sub ($status_reason_ar) { say 'WebSocket finished OK' },\n        sub ($err) {\n            warn \"WebSocket non-success: $err\";\n        },\n    )-\u003efinally($cv);\n\nLook at [Net::Libwebsockets::WebSocket::Client](https://metacpan.org/pod/Net%3A%3ALibwebsockets%3A%3AWebSocket%3A%3AClient) for documentation\nof the above.\n\n# DESCRIPTION\n\n\u003cdiv\u003e\n    \u003ca href='https://coveralls.io/github/FGasper/p5-Net-Libwebsockets?branch=master'\u003e\u003cimg src='https://coveralls.io/repos/github/FGasper/p5-Net-Libwebsockets/badge.svg?branch=master' alt='Coverage Status' /\u003e\u003c/a\u003e\n\u003c/div\u003e\n\nThis module provides a Perl binding to\n[libwebsockets](https://libwebsockets.org/) (aka “LWS”), a C\nlibrary that provides client and server implementations of\n[WebSocket](https://www.rfc-editor.org/rfc/rfc6455.html)\nand [HTTP/2](https://httpwg.org/specs/rfc7540.html), among other\nprotocols.\n\n# STATUS\n\nThis module currently only implements WebSocket, and only as a client.\n(cf. [Net::Libwebsockets::WebSocket::Client](https://metacpan.org/pod/Net%3A%3ALibwebsockets%3A%3AWebSocket%3A%3AClient))\nThis is all **EXPERIMENTAL**, so all interfaces are subject to change,\nand any part of it can blow up in any way at any time.\n\nThat said, it’s been in development for some time, and it should be\nuseful enough to play with. [Error reporting](#errors) and\n[memory-leak detection](#memory-leak-detection)\nhave received especial care. LWS itself is used on tens of millions\nof devices, so any issues you encounter will likely be solvable readily\nby fixing this little module rather than delving into LWS.\n\nNote the following:\n\n- LWS version 4.3.0 or later is required.\n(As of this writing that’s the latest release.)\n- Some LWS builds lack useful stuff like WebSocket compression\nor non-blocking DNS queries. If in doubt, check your build.\n- There’s currently no maximum WebSocket message size.\n(That’s less of a concern for clients than it is for servers, of course.)\n\n# BUILDING\n\nThis module, as of this writing, needs a newer LWS build than most OSes\nprovide. To use Net::Libwebsockets, then, you may need to build your own\nLWS, then link this module against that build. To simplify that,\nyou can define a `LWS_BUILD_DIR` environment variable when you run\nthis module’s provided `Makefile.PL` script. `LWS_BUILD_DIR` tells\n`Makefile.PL` where to find your custom LWS build, which avoids the\nneed to install your custom build globally.\n\nAs of this writing\n[LWS’s upstream main branch](https://github.com/warmcat/libwebsockets/tree/main)\nincludes several useful fixes \u0026 improvements beyond what the latest\nrelease provides. It is thus recommended to build from that branch.\n\n# EVENT LOOP SUPPORT\n\nThis module supports most of Perl’s popular event loops via either\n[IO::Async](https://metacpan.org/pod/IO%3A%3AAsync), [Mojolicious](https://metacpan.org/pod/Mojolicious), or [AnyEvent](https://metacpan.org/pod/AnyEvent).\n\n# LOGGING\n\nLWS historically configured its logging globally; i.e., all LWS contexts\nwithin a process shared the same logging configuration.\n\nLWS 4.3.0 introduced context-specific logging alongside the old\nglobal-state functions. As of this writing, though, most of LWS’s internal\nlogger calls still use the older functions, which means those log\nstatements will go out however the global logging is configured, regardless\nof whether there’s a context-specific logging configuration for a given\naction. Conversion of existing log statements is ongoing.\n\nThis library supports both LWS’s old/global and new/contextual logging.\nSee [Net::Libwebsockets::Logger](https://metacpan.org/pod/Net%3A%3ALibwebsockets%3A%3ALogger) and `set_log_level()` below for more\ndetails.\n\n# ERRORS\n\nMost of this module’s errors are instances of\n[Net::Libwebsockets::X::Base](https://metacpan.org/pod/Net%3A%3ALibwebsockets%3A%3AX%3A%3ABase), which extends [X::Tiny::Base](https://metacpan.org/pod/X%3A%3ATiny%3A%3ABase). Errors that\nmore likely indicate programmer misuse than runtime failure are more apt\nto be simple strings.\n\n# MEMORY LEAK DETECTION\n\n`DESTROY()` at global destruction usually means either you stored the\nDESTROYed object in a global, or you have a memory leak. To silence the\nwarning in the former case, just clear your global at END time. In the\nlatter case, though, you have to fix the memory leak.\n\nAs an aid in identifying these cases, most objects here emit a warning if\ntheir `DESTROY()` method runs at global-destruction time.\n\n# CONSTANTS\n\nThis package exposes the following constants. For their meanings\nsee LWS’s documentation.\n\n- `HAS_PMD` - A boolean that indicates whether\nWebSocket compression (i.e., [per-message deflate](https://datatracker.ietf.org/doc/html/rfc7692#page-12), or `PMD`) is available.\n- Log levels: `LLL_ERR` et al. ([See here for the others.](https://libwebsockets.org/lws-api-doc-master/html/group__log.html))\n- TLS/SSL-related: `LCCSCF_ALLOW_SELFSIGNED`, `LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK`, `LCCSCF_ALLOW_EXPIRED`, `LCCSCF_ALLOW_INSECURE`\n- WebSocket close codes:\n    - `CLOSE_STATUS_NORMAL`: 1000\n    - `CLOSE_STATUS_GOINGAWAY`: 1001\n    - `CLOSE_STATUS_PROTOCOL_ERR`: 1002\n    - `CLOSE_STATUS_UNACCEPTABLE_OPCODE`: 1003\n    - `CLOSE_STATUS_NO_STATUS`: 1005\n    - `CLOSE_STATUS_ABNORMAL_CLOSE`: 1006\n    - `CLOSE_STATUS_INVALID_PAYLOAD`: 1007\n    - `CLOSE_STATUS_POLICY_VIOLATION`: 1008\n    - `CLOSE_STATUS_MESSAGE_TOO_LARGE`: 1009\n    - `CLOSE_STATUS_EXTENSION_REQUIRED`: 1010\n    - `CLOSE_STATUS_UNEXPECTED_CONDITION`: 1011\n\n# FUNCTIONS\n\nMost of this distribution’s controls lie in submodules; however,\nthe present package does expose some functionality of its own:\n\n## set\\_log\\_level( $LEVEL )\n\nSets LWS’s global log level, which is the bitwise-OR of the log-level\nconstants referenced above. For example, to see only errors and warnings\nyou can do:\n\n    Net::Libwebsockets::set_log_level(\n        Net::Libwebsockets::LLL_ERR | Net::Libwebsockets::LLL_WARN\n    );\n\nLWS allows setting a callback to direct log output to someplace other\nthan STDERR. This library, though, does not (currently?) support that\nexcept via contextual logging ([Net::Libwebsockets::Logger](https://metacpan.org/pod/Net%3A%3ALibwebsockets%3A%3ALogger)).\n\n# SEE ALSO\n\nOther CPAN WebSocket implementations include:\n\n- [Net::WebSocket](https://metacpan.org/pod/Net%3A%3AWebSocket) - Maximum flexibility.\n- [Mojolicious](https://metacpan.org/pod/Mojolicious) - Maximum simplicity.\n- [Net::WebSocket::Server](https://metacpan.org/pod/Net%3A%3AWebSocket%3A%3AServer) - Server implementation only.\n(No relation to [Net::WebSocket](https://metacpan.org/pod/Net%3A%3AWebSocket)!)\n- [Net::Async::WebSocket](https://metacpan.org/pod/Net%3A%3AAsync%3A%3AWebSocket) - WebSocket for [IO::Async](https://metacpan.org/pod/IO%3A%3AAsync)\n- [AnyEvent::WebSocket::Client](https://metacpan.org/pod/AnyEvent%3A%3AWebSocket%3A%3AClient) - [AnyEvent](https://metacpan.org/pod/AnyEvent) WS server\n- [AnyEvent::WebSocket::Server](https://metacpan.org/pod/AnyEvent%3A%3AWebSocket%3A%3AServer)  - [AnyEvent](https://metacpan.org/pod/AnyEvent) WS client\n- [Protocol::WebSocket](https://metacpan.org/pod/Protocol%3A%3AWebSocket) - Early, bare-bones, used in some of the\nothers.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffgasper%2Fp5-net-libwebsockets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffgasper%2Fp5-net-libwebsockets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffgasper%2Fp5-net-libwebsockets/lists"}