dev-master
9999999-dev http://socketo.meBase Reamp server component
MIT
The Requires
- php >=7.0
- amphp/socket ^0.10.5
The Development Requires
by Chris Boden
server websocket sockets amphp ratchet websockets reamp
Base Reamp server component
What is ReAmp ? It is port of Ratchet to amphp. It was created as fork of original project but add some new features: * Use different namespace * Use amphp by default * Php7 support * Phpunit 6 * Code style, (*1)
There still lack of features but will be done in future: * http request body support (post/put/create) * http request pipeline support * psr logging support * better parsing similar to amp/aerys style * support async and promises in components, (*2)
This is base component of reamp. It used for creating socket server, (*3)
This package can be installed as a Composer dependency., (*4)
composer require reamp/server
Documentation can be found on Ratchet's website: with some exceptions as well as in the ./docs
directory., (*5)
This example create simple chat server on port 8080, (*6)
<?php use Reamp\Server\IoServer; use Reamp\Server\IoServerInterface; use Reamp\Server\ConnectionInterface; // Make sure composer dependencies have been installed require __DIR__ . '/vendor/autoload.php'; /** * chat.php * Send any incoming messages to all connected clients (except sender) */ class MyChat implements IoServerInterface { protected $clients; public function __construct() { $this->clients = new \SplObjectStorage; } public function onOpen(ConnectionInterface $conn) { $this->clients->attach($conn); } public function onMessage(ConnectionInterface $from, $msg) { foreach ($this->clients as $client) { if ($from != $client) { $client->send($msg); } } } public function onClose(ConnectionInterface $conn) { $this->clients->detach($conn); } public function onError(ConnectionInterface $conn, \Throwable $e) { $conn->close(); } } // Run the server application through the WebSocket protocol on port 8080 $app = IoServer::factory(new MyChat(), 8080, 'localhost'); IoServer::run();
$ php chat.php
Further examples can be found in the ./examples
directory of this repository as well as in the Ratchet repository., (*7)
Base Reamp server component
MIT
server websocket sockets amphp ratchet websockets reamp