All Projects → hoaproject → Websocket

hoaproject / Websocket

The Hoa\Websocket library.

Projects that are alternatives of or similar to Websocket

Jiny
Lightweight, modern, simple JVM web framework for rapid development in the API era
Stars: ✭ 40 (-90.5%)
Mutual labels:  websocket, websocket-server, websocket-client
Sketchpad
Sketchpad is fully customisable collaborative whiteboard plugin written in pure JavaScript.
Stars: ✭ 85 (-79.81%)
Mutual labels:  websocket, websocket-server, websocket-client
Websocket
A PHP implementation of WebSocket.
Stars: ✭ 54 (-87.17%)
Mutual labels:  websocket, websocket-server, websocket-client
Autobahn Testsuite
Autobahn WebSocket protocol testsuite
Stars: ✭ 603 (+43.23%)
Mutual labels:  websocket, websocket-server, websocket-client
Libhv
🔥 比libevent、libuv更易用的国产网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket client/server.
Stars: ✭ 3,355 (+696.91%)
Mutual labels:  websocket, websocket-server, websocket-client
Awesome Websockets
A curated list of Websocket libraries and resources.
Stars: ✭ 850 (+101.9%)
Mutual labels:  websocket, websocket-server, websocket-client
Websockets
Library for building WebSocket servers and clients in Python
Stars: ✭ 3,724 (+784.56%)
Mutual labels:  websocket, websocket-server, websocket-client
Oatpp Websocket
oatpp-websocket submodule.
Stars: ✭ 26 (-93.82%)
Mutual labels:  websocket, websocket-server, websocket-client
Embedded Jetty Websocket Examples
Embedded Jetty WebSocket Examples
Stars: ✭ 159 (-62.23%)
Mutual labels:  websocket, websocket-server, websocket-client
Php Wss
Web-socket server/client with multi-process and parse templates support on server and send/receive options on client
Stars: ✭ 117 (-72.21%)
Mutual labels:  websocket, websocket-server, websocket-client
Deno Websocket
🦕 A simple WebSocket library like ws of node.js library for deno
Stars: ✭ 74 (-82.42%)
Mutual labels:  websocket, websocket-server, websocket-client
Beast
HTTP and WebSocket built on Boost.Asio in C++11
Stars: ✭ 3,241 (+669.83%)
Mutual labels:  websocket, websocket-server, websocket-client
Arduinowebsockets
arduinoWebSockets
Stars: ✭ 1,265 (+200.48%)
Mutual labels:  websocket, websocket-server, websocket-client
Cwebsocket
cWebsocket is lightweight websocket server library
Stars: ✭ 241 (-42.76%)
Mutual labels:  library, websocket, websocket-server
Ws
Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
Stars: ✭ 17,419 (+4037.53%)
Mutual labels:  websocket, websocket-server, websocket-client
Ustring
The Hoa\Ustring library.
Stars: ✭ 403 (-4.28%)
Mutual labels:  hoa, library
Websockex
An Elixir Websocket Client
Stars: ✭ 305 (-27.55%)
Mutual labels:  websocket, websocket-client
Protocol
The Hoa\Protocol library.
Stars: ✭ 308 (-26.84%)
Mutual labels:  hoa, library
Stream
The Hoa\Stream library.
Stars: ✭ 313 (-25.65%)
Mutual labels:  hoa, library
Python Slack Sdk
Slack Developer Kit for Python
Stars: ✭ 3,307 (+685.51%)
Mutual labels:  websocket, websocket-client

Hoa


Build status Code coverage Packagist License

Hoa is a modular, extensible and structured set of PHP libraries.
Moreover, Hoa aims at being a bridge between industrial and research worlds.

Hoa\Websocket

Help on IRC Help on Gitter Documentation Board

This library allows to manipulate the WebSocket protocol and proposes a server and a client. It supports two specifications RFC6455 and Hybi (at the same time).

Learn more.

Installation

With Composer, to include this library into your dependencies, you need to require hoa/websocket:

$ composer require hoa/websocket '~3.0'

For more installation procedures, please read the Source page.

Testing

Before running the test suites, the development dependencies must be installed:

$ composer install

Then, to run all the test suites:

$ vendor/bin/hoa test:run

For more information, please read the contributor guide.

Quick usage

As a quick overview, we propose to start a websocket server and echo messages. The class Hoa\Websocket\Server proposes six listeners: open, message, binary-message, ping, close and error. Thus:

$websocket = new Hoa\Websocket\Server(
    new Hoa\Socket\Server('ws://127.0.0.1:8889')
);
$websocket->on('open', function (Hoa\Event\Bucket $bucket) {
    echo 'new connection', "\n";

    return;
});
$websocket->on('message', function (Hoa\Event\Bucket $bucket) {
    $data = $bucket->getData();
    echo '> message ', $data['message'], "\n";
    $bucket->getSource()->send($data['message']);
    echo '< echo', "\n";

    return;
});
$websocket->on('close', function (Hoa\Event\Bucket $bucket) {
    echo 'connection closed', "\n";

    return;
});
$websocket->run();

Finally, we have to write a client in HTML and Javascript:

<input type="text" id="input" placeholder="Message…" />
<hr />
<pre id="output"></pre>

<script>
  var host   = 'ws://127.0.0.1:8889';
  var socket = null;
  var input  = document.getElementById('input');
  var output = document.getElementById('output');
  var print  = function (message) {
      var samp       = document.createElement('samp');
      samp.innerHTML = message + '\n';
      output.appendChild(samp);

      return;
  };

  input.addEventListener('keyup', function (evt) {
      if (13 === evt.keyCode) {
          var msg = input.value;

          if (!msg) {
              return;
          }

          try {
              socket.send(msg);
              input.value = '';
              input.focus();
          } catch (e) {
              console.log(e);
          }

          return;
      }
  });

  try {
      socket = new WebSocket(host);
      socket.onopen = function () {
          print('connection is opened');
          input.focus();

          return;
      };
      socket.onmessage = function (msg) {
          print(msg.data);

          return;
      };
      socket.onclose = function () {
          print('connection is closed');

          return;
      };
  } catch (e) {
      console.log(e);
  }
</script>

Here we are. All sent messages are echoed.

Awecode

The following awecodes show this library in action:

  • Hoa\Websocket: why and how to use Hoa\Websocket\Server and Hoa\Websocket\Client? A simple example will illustrate the WebSocket protocol.

Documentation

The hack book of Hoa\Websocket contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open

More documentation can be found on the project's website: hoa-project.net.

Getting help

There are mainly two ways to get help:

Contribution

Do you want to contribute? Thanks! A detailed contributor guide explains everything you need to know.

License

Hoa is under the New BSD License (BSD-3-Clause). Please, see LICENSE for details.

Related projects

The following projects are using this library:

  • Marvirc, A dead simple, extremely modular and blazing fast IRC bot,
  • WellCommerce, Modern e-commerce engine built on top of Symfony 3 full-stack framework.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].