{"id":33018396,"url":"https://github.com/hoaproject/Websocket","last_synced_at":"2025-11-16T14:00:37.401Z","repository":{"id":4401641,"uuid":"5538859","full_name":"hoaproject/Websocket","owner":"hoaproject","description":"The Hoa\\Websocket library.","archived":true,"fork":false,"pushed_at":"2021-04-28T21:38:16.000Z","size":337,"stargazers_count":421,"open_issues_count":27,"forks_count":74,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-09-21T06:30:02.266Z","etag":null,"topics":["hoa","library","php","rfc-3629","rfc-3986","rfc-6455","websocket","websocket-cli","websocket-client","websocket-server"],"latest_commit_sha":null,"homepage":"https://hoa-project.net/","language":"PHP","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/hoaproject.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2012-08-24T10:31:39.000Z","updated_at":"2025-08-27T12:04:25.000Z","dependencies_parsed_at":"2022-08-21T12:20:43.238Z","dependency_job_id":null,"html_url":"https://github.com/hoaproject/Websocket","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/hoaproject/Websocket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FWebsocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FWebsocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FWebsocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FWebsocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoaproject","download_url":"https://codeload.github.com/hoaproject/Websocket/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FWebsocket/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284719042,"owners_count":27052182,"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","status":"online","status_checked_at":"2025-11-16T02:00:05.974Z","response_time":65,"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":["hoa","library","php","rfc-3629","rfc-3986","rfc-6455","websocket","websocket-cli","websocket-client","websocket-server"],"created_at":"2025-11-13T18:00:39.567Z","updated_at":"2025-11-16T14:00:37.393Z","avatar_url":"https://github.com/hoaproject.png","language":"PHP","funding_links":[],"categories":["Event","事件","Table of Contents","事件 Event","事件( Event )"],"sub_categories":["Event"],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://static.hoa-project.net/Image/Hoa.svg\" alt=\"Hoa\" width=\"250px\" /\u003e\n\u003c/p\u003e\n\n---\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://travis-ci.org/hoaproject/Websocket\"\u003e\u003cimg src=\"https://img.shields.io/travis/hoaproject/Websocket/master.svg\" alt=\"Build status\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://coveralls.io/github/hoaproject/Websocket?branch=master\"\u003e\u003cimg src=\"https://img.shields.io/coveralls/hoaproject/Websocket/master.svg\" alt=\"Code coverage\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://packagist.org/packages/hoa/websocket\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/hoa/websocket.svg\" alt=\"Packagist\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://hoa-project.net/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/packagist/l/hoa/websocket.svg\" alt=\"License\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  Hoa is a \u003cstrong\u003emodular\u003c/strong\u003e, \u003cstrong\u003eextensible\u003c/strong\u003e and\n  \u003cstrong\u003estructured\u003c/strong\u003e set of PHP libraries.\u003cbr /\u003e\n  Moreover, Hoa aims at being a bridge between industrial and research worlds.\n\u003c/p\u003e\n\n# Hoa\\Websocket\n\n[![Help on IRC](https://img.shields.io/badge/help-%23hoaproject-ff0066.svg)](https://webchat.freenode.net/?channels=#hoaproject)\n[![Help on Gitter](https://img.shields.io/badge/help-gitter-ff0066.svg)](https://gitter.im/hoaproject/central)\n[![Documentation](https://img.shields.io/badge/documentation-hack_book-ff0066.svg)](https://central.hoa-project.net/Documentation/Library/Websocket)\n[![Board](https://img.shields.io/badge/organisation-board-ff0066.svg)](https://waffle.io/hoaproject/websocket)\n\nThis library allows to manipulate the WebSocket protocol and proposes a server\nand a client. It supports two specifications\n[RFC6455](https://tools.ietf.org/html/rfc6455) and\n[Hybi](https://tools.ietf.org/wg/hybi/draft-ietf-hybi-thewebsocketprotocol/) (at\nthe same time).\n\n[Learn more](https://central.hoa-project.net/Documentation/Library/Websocket).\n\n## Installation\n\nWith [Composer](https://getcomposer.org/), to include this library into\nyour dependencies, you need to\nrequire [`hoa/websocket`](https://packagist.org/packages/hoa/websocket):\n\n```sh\n$ composer require hoa/websocket '~3.0'\n```\n\nFor more installation procedures, please read [the Source\npage](https://hoa-project.net/Source.html).\n\n## Testing\n\nBefore running the test suites, the development dependencies must be installed:\n\n```sh\n$ composer install\n```\n\nThen, to run all the test suites:\n\n```sh\n$ vendor/bin/hoa test:run\n```\n\nFor more information, please read the [contributor\nguide](https://hoa-project.net/Literature/Contributor/Guide.html).\n\n## Quick usage\n\nAs a quick overview, we propose to start a websocket server and echo messages.\nThe class `Hoa\\Websocket\\Server` proposes six listeners: `open`, `message`,\n`binary-message`, `ping`, `close` and `error`. Thus:\n\n```php\n$websocket = new Hoa\\Websocket\\Server(\n    new Hoa\\Socket\\Server('ws://127.0.0.1:8889')\n);\n$websocket-\u003eon('open', function (Hoa\\Event\\Bucket $bucket) {\n    echo 'new connection', \"\\n\";\n\n    return;\n});\n$websocket-\u003eon('message', function (Hoa\\Event\\Bucket $bucket) {\n    $data = $bucket-\u003egetData();\n    echo '\u003e message ', $data['message'], \"\\n\";\n    $bucket-\u003egetSource()-\u003esend($data['message']);\n    echo '\u003c echo', \"\\n\";\n\n    return;\n});\n$websocket-\u003eon('close', function (Hoa\\Event\\Bucket $bucket) {\n    echo 'connection closed', \"\\n\";\n\n    return;\n});\n$websocket-\u003erun();\n```\n\nFinally, we have to write a client in HTML and Javascript:\n\n```html\n\u003cinput type=\"text\" id=\"input\" placeholder=\"Message…\" /\u003e\n\u003chr /\u003e\n\u003cpre id=\"output\"\u003e\u003c/pre\u003e\n\n\u003cscript\u003e\n  var host   = 'ws://127.0.0.1:8889';\n  var socket = null;\n  var input  = document.getElementById('input');\n  var output = document.getElementById('output');\n  var print  = function (message) {\n      var samp       = document.createElement('samp');\n      samp.innerHTML = message + '\\n';\n      output.appendChild(samp);\n\n      return;\n  };\n\n  input.addEventListener('keyup', function (evt) {\n      if (13 === evt.keyCode) {\n          var msg = input.value;\n\n          if (!msg) {\n              return;\n          }\n\n          try {\n              socket.send(msg);\n              input.value = '';\n              input.focus();\n          } catch (e) {\n              console.log(e);\n          }\n\n          return;\n      }\n  });\n\n  try {\n      socket = new WebSocket(host);\n      socket.onopen = function () {\n          print('connection is opened');\n          input.focus();\n\n          return;\n      };\n      socket.onmessage = function (msg) {\n          print(msg.data);\n\n          return;\n      };\n      socket.onclose = function () {\n          print('connection is closed');\n\n          return;\n      };\n  } catch (e) {\n      console.log(e);\n  }\n\u003c/script\u003e\n```\n\nHere we are. All sent messages are echoed.\n\n## Awecode\n\nThe following awecodes show this library in action:\n\n  * [`Hoa\\Websocket`](https://hoa-project.net/Awecode/Websocket.html):\n    *why and how to use `Hoa\\Websocket\\Server` and `Hoa\\Websocket\\Client`? A\n    simple example will illustrate the WebSocket protocol*.\n\n## Documentation\n\nThe\n[hack book of `Hoa\\Websocket`](https://central.hoa-project.net/Documentation/Library/Websocket) contains\ndetailed information about how to use this library and how it works.\n\nTo generate the documentation locally, execute the following commands:\n\n```sh\n$ composer require --dev hoa/devtools\n$ vendor/bin/hoa devtools:documentation --open\n```\n\nMore documentation can be found on the project's website:\n[hoa-project.net](https://hoa-project.net/).\n\n## Getting help\n\nThere are mainly two ways to get help:\n\n  * On the [`#hoaproject`](https://webchat.freenode.net/?channels=#hoaproject)\n    IRC channel,\n  * On the forum at [users.hoa-project.net](https://users.hoa-project.net).\n\n## Contribution\n\nDo you want to contribute? Thanks! A detailed [contributor\nguide](https://hoa-project.net/Literature/Contributor/Guide.html) explains\neverything you need to know.\n\n## License\n\nHoa is under the New BSD License (BSD-3-Clause). Please, see\n[`LICENSE`](https://hoa-project.net/LICENSE) for details.\n\n## Related projects\n\nThe following projects are using this library:\n\n  * [Marvirc](https://github.com/Hywan/Marvirc), A dead simple,\n    extremely modular and blazing fast IRC bot,\n  * [WellCommerce](http://wellcommerce.org/), Modern e-commerce engine\n    built on top of Symfony 3 full-stack framework.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoaproject%2FWebsocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoaproject%2FWebsocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoaproject%2FWebsocket/lists"}