All Projects → ratchetphp → Pawl

ratchetphp / Pawl

Licence: mit
Asynchronous WebSocket client

Projects that are alternatives of or similar to Pawl

reactive-streams-for-java-developers
No description or website provided.
Stars: ✭ 16 (-96.43%)
Mutual labels:  websockets, websocket-client
Beast
HTTP and WebSocket built on Boost.Asio in C++11
Stars: ✭ 3,241 (+623.44%)
Mutual labels:  websockets, websocket-client
LazWebsockets
Websocket Server and Client Library written in Lazarus
Stars: ✭ 51 (-88.62%)
Mutual labels:  websockets, websocket-client
general-angular
Realtime Angular Admin/CRUD Front End App
Stars: ✭ 24 (-94.64%)
Mutual labels:  websockets, websocket-client
Websockets
Library for building WebSocket servers and clients in Python
Stars: ✭ 3,724 (+731.25%)
Mutual labels:  websockets, websocket-client
text
An experiment with WebSockets and the human condition.
Stars: ✭ 51 (-88.62%)
Mutual labels:  websockets, websocket-client
Node Slack Sdk
Slack Developer Kit for Node.js
Stars: ✭ 2,988 (+566.96%)
Mutual labels:  websockets, websocket-client
Async Tungstenite
Async binding for Tungstenite, the Lightweight stream-based WebSocket implementation
Stars: ✭ 207 (-53.79%)
Mutual labels:  async, websockets
Python Slack Sdk
Slack Developer Kit for Python
Stars: ✭ 3,307 (+638.17%)
Mutual labels:  websockets, websocket-client
Websocket Client
🔧 .NET/C# websocket client library
Stars: ✭ 297 (-33.71%)
Mutual labels:  websockets, websocket-client
remoting
Jetlang Remoting - asynchronous distributed messaging
Stars: ✭ 27 (-93.97%)
Mutual labels:  websockets, websocket-client
Ntex
framework for composable networking services
Stars: ✭ 381 (-14.96%)
Mutual labels:  async, websockets
System.Net.WebSockets.Client.Managed
Microsoft's managed implementation of System.Net.WebSockets.ClientWebSocket tweaked for use on Windows 7 and .NET 4.5
Stars: ✭ 41 (-90.85%)
Mutual labels:  websockets, websocket-client
EthernetWebServer
This is simple yet complete WebServer library for AVR, Portenta_H7, Teensy, SAM DUE, SAMD21/SAMD51, nRF52, STM32, RP2040-based, etc. boards running Ethernet shields. The functions are similar and compatible to ESP8266/ESP32 WebServer libraries to make life much easier to port sketches from ESP8266/ESP32. Coexisting now with `ESP32 WebServer` and…
Stars: ✭ 118 (-73.66%)
Mutual labels:  websockets, websocket-client
Brayns
Visualizer for large-scale and interactive ray-tracing of neurons
Stars: ✭ 232 (-48.21%)
Mutual labels:  async, websockets
Aiowebsocket
Async WebSocket Client. Advantage: Flexible Lighter and Faster
Stars: ✭ 263 (-41.29%)
Mutual labels:  async, websockets
Actix Web
Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.
Stars: ✭ 12,723 (+2739.96%)
Mutual labels:  async, websockets
Http Kit
http-kit is a minimalist, event-driven, high-performance Clojure HTTP server/client library with WebSocket and asynchronous support
Stars: ✭ 2,234 (+398.66%)
Mutual labels:  async, websockets
Microwebsrv2
The last Micro Web Server for IoTs (MicroPython) or large servers (CPython), that supports WebSockets, routes, template engine and with really optimized architecture (mem allocations, async I/Os). Ready for ESP32, STM32 on Pyboard, Pycom's chipsets (WiPy, LoPy, ...). Robust, efficient and documented!
Stars: ✭ 295 (-34.15%)
Mutual labels:  async, websockets
Saea
SAEA.Socket is a high-performance IOCP framework TCP based on dotnet standard 2.0; Src contains its application test scenarios, such as websocket,rpc, redis driver, MVC WebAPI, lightweight message server, ultra large file transmission, etc. SAEA.Socket是一个高性能IOCP框架的 TCP,基于dotnet standard 2.0;Src中含有其应用测试场景,例如websocket、rpc、redis驱动、MVC WebAPI、轻量级消息服务器、超大文件传输等
Stars: ✭ 318 (-29.02%)
Mutual labels:  websockets, websocket-client

Pawl

Autobahn Testsuite Build Status

An asynchronous WebSocket client in PHP

Install via composer:

composer require ratchet/pawl

Usage

Pawl as a standalone app: Connect to an echo server, send a message, display output, close connection:

<?php

    require __DIR__ . '/vendor/autoload.php';

    \Ratchet\Client\connect('wss://echo.websocket.org:443')->then(function($conn) {
        $conn->on('message', function($msg) use ($conn) {
            echo "Received: {$msg}\n";
            $conn->close();
        });

        $conn->send('Hello World!');
    }, function ($e) {
        echo "Could not connect: {$e->getMessage()}\n";
    });

Classes

There are 3 primary classes to be aware of and use in Pawl:

Connector:

Makes HTTP requests to servers returning a promise that, if successful, will resolve to a WebSocket object. A connector is configured via its constructor and a request is made by invoking the class. Multiple connections can be established through a single connector. The invoke mehtod has 3 parameters:

  • $url: String; A valid uri string (starting with ws:// or wss://) to connect to (also accepts PSR-7 Uri object)
  • $subProtocols: Array; An optional indexed array of WebSocket sub-protocols to negotiate to the server with. The connection will fail if the client and server can not agree on one if any are provided
  • $headers: Array; An optional associative array of additional headers requests to use when initiating the handshake. A common header to set is Origin
WebSocket:

This is the object used to interact with a WebSocket server. It has two methods: send and close. It has two public properties: request and response which are PSR-7 objects representing the client and server side HTTP handshake headers used to establish the WebSocket connection.

Message:

This is the object received from a WebSocket server. It has a __toString method which is how most times you will want to access the data received. If you need to do binary messaging you will most likely need to use methods on the object.

Example

A more in-depth example using explicit interfaces: Requesting sub-protocols, and sending custom headers while using a specific React Event Loop:

<?php

    require __DIR__ . '/vendor/autoload.php';

    $loop = \React\EventLoop\Factory::create();
    $reactConnector = new \React\Socket\Connector($loop, [
        'dns' => '8.8.8.8',
        'timeout' => 10
    ]);
    $connector = new \Ratchet\Client\Connector($loop, $reactConnector);

    $connector('ws://127.0.0.1:9000', ['protocol1', 'subprotocol2'], ['Origin' => 'http://localhost'])
    ->then(function(Ratchet\Client\WebSocket $conn) {
        $conn->on('message', function(\Ratchet\RFC6455\Messaging\MessageInterface $msg) use ($conn) {
            echo "Received: {$msg}\n";
            $conn->close();
        });

        $conn->on('close', function($code = null, $reason = null) {
            echo "Connection closed ({$code} - {$reason})\n";
        });

        $conn->send('Hello World!');
    }, function(\Exception $e) use ($loop) {
        echo "Could not connect: {$e->getMessage()}\n";
        $loop->stop();
    });

    $loop->run();
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].