2017 © Pedro Peláez
 

library server

Base Reamp server component

image

reamp/server

Base Reamp server component

  • Monday, May 28, 2018
  • by Ekstazi
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

ReAmp

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)

Reamp server

This is base component of reamp. It used for creating socket server, (*3)

Installation

This package can be installed as a Composer dependency., (*4)

composer require reamp/server

Documentation

Documentation can be found on Ratchet's website: with some exceptions as well as in the ./docs directory., (*5)

Requirements

  • PHP 7.0+
  • Shell access is required and root access is recommended.

Examples

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)

The Versions

28/05 2018

dev-master

9999999-dev http://socketo.me

Base Reamp server component

  Sources   Download

MIT

The Requires

 

The Development Requires

server websocket sockets amphp ratchet websockets reamp