GithubHelp home page GithubHelp logo

ratchetphp / ratchet Goto Github PK

View Code? Open in Web Editor NEW
6.2K 6.2K 695.0 1.25 MB

Asynchronous WebSocket server

Home Page: http://socketo.me

License: MIT License

Makefile 0.93% PHP 99.07%
async php ratchet websocket websockets

ratchet's People

Contributors

barbarrosa avatar bobvandevijver avatar cboden avatar clue avatar gerritdrost avatar igorw avatar ikovalyov avatar im0rtality avatar joelwurtz avatar lyrixx avatar maggedotno avatar mbabker avatar mbonneau avatar mikealmond avatar minifets avatar nineff avatar nyholm avatar pborreli avatar rafaelka avatar romainneutron avatar ruslan-naryzhnyi avatar samizdam avatar sartoshi-foot-dao avatar simpod avatar skroczek avatar thpl avatar vincentdieltiens avatar vkartaviy avatar xavierbriand avatar yurist-85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ratchet's Issues

Connection Cleanup

Test changing Connection object to pretty much a POPO (Plain Old PHP Object {StdClass}). Have IOServerComponent/Transport set the remoteAddress and resourceId as properties instead of the Connection::get???() trying to figure out based on the Socket transport type. This also means removing the magic methods, which should fix lambda calls in WAMP's setPrefix(). Need to make sure no parameters are set w/ Closures that execute on __get() however.

This should allow Connection to be a true Proxy object and let the Transport class handle I/O and should be easier to maintain, document and handle.

Sync'd subscriptions

When WampServer receives a subscription from a client it attaches a Connection to a Topic in two places. The developer is able to remove a Connection from a Topic but currently doing so will not remove the reference in the TopicManager.

145 Character Message Limit

Just wondering what the reasoning behind the 145 character limit was? I have used other websocket implementations which do not have this limit.

Is there any way I can contribute to fixing this?

Cheers

Command Cleanup

  • Move SendMessage and CloseConnection to the Server namespace, probably need different ones per transport used
  • Change Factory::addActionPath() to be static so all new factories already have Action paths loaded
  • In the Component __constructs() call Factory::addActionPath() so the user doesn't have to register Actions, they're just automatically loaded when needed

Control Frames

Complete the WebSocket control frames:

  • Close
  • Ping
  • Pong

Docs: Push tutorial improvements

  • zmq should not bind to a public port. You should bind to the private port on the internal network instead.
  • Push should be in the MyApp namespace for consistency with the first example.
  • Socket server should bind to port 8000 for consistency and so no sudo is needed.
  • onPublish is missing two args (as reported by Mr. Cloud on the mailing list).

Cannot install with react/zmq

Because of a dependecy bump in react/zmq (https://github.com/react-php/zmq/commit/842b6ed53d2b2421eed23efeee0fb8ab0a9f196c#composer.json) to react/event-loop-0.2.* it cannot be installed together with cboden/Ratchet which depends on react/event-loop-0.1.*

This breaks the tutorial http://socketo.me/docs/push

$ cat composer.json
{
"require": {
"cboden/Ratchet": "0.2.*",
"react/zmq": "dev-master"
}
}

$ php composer.phar install
Loading composer repositories with package information
Installing dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- react/react v0.1.1 requires silex/silex 1.0.* -> no matching package found.
- react/react v0.1.0 requires silex/silex 1.0.* -> no matching package found.
- Conclusion: don't install cboden/Ratchet v0.2.1
- Conclusion: don't install react/event-loop v0.1.1
- Installation request for cboden/ratchet 0.2.* -> satisfiable by cboden/Ratchet v0.2.0, cboden/Ratchet v0.2.1.
- Installation request for react/zmq dev-master -> satisfiable by react/zmq dev-master.
- cboden/Ratchet v0.2.0 requires react/socket 0.1.* -> satisfiable by react/react v0.1.0, react/react v0.1.1, react/socket v0.1.0, react/socket v0.1.1.
- react/socket v0.1.0 requires react/event-loop 0.1.* -> satisfiable by react/event-loop v0.1.0, react/event-loop v0.1.1, react/react v0.1.0, react/react v0.1.1.
- react/socket v0.1.1 requires react/event-loop 0.1.* -> satisfiable by react/event-loop v0.1.0, react/event-loop v0.1.1, react/react v0.1.0, react/react v0.1.1.
- Conclusion: don't install react/event-loop v0.1.0

Potential causes:

Read http://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

Can Ratchet server send a message to client (for example, iPhone App)?

Hello, Chris. First of all I want to say 'thank you' for your work.

I've found out that 'MessageComponentInterface' has 'onMessage' function that is called every time a client sent a massage. And the server can send an answer back to this client (and other connected clients).

But I need an ability to send a massage from server to client without client send a massage first.

For example. iPhone App has a feed of photos. And when a new photo is added by another iPhone App, this photo will be upload to the server, processed, and need to be shown on the first iPhone App immediately after processing. So, the Ratchet server has to check for new photos and send this photo to iPhone App. Of course, Ratchet server has not to check for new photo, but it need to send a new data (photos) to iPhone Apps.

How can I solve this problem? Thank you.

Documentation

My highest priority is to re-write lost documentation (sorry, Wiki is out of date) and publish it on the website.

Flash Policy Component

Move the FlashPolicy class to the Ratchet repo under Ratchet\Component\Server\FlashPolicyComponent.

Create a static factory method called fromFile($file) to import an existing policy file.

Add easy to understand methods to piece together a policy without the developer requiring knowledge of the policy XML schema.

This in Ratchet will easily allow developers to support the Flash WebSocket polyfill.

Implement SSL-Support

I just discovered Ratchet some hours ago and really like the project, its structure, the usage of React, etc! Very good job!
I also implemented some test server to try it out and it really works nicely.

The only feature missing for us is currently SSL-Support. Do you consider adding support for SSL?
I found this: http://code.google.com/p/phpws/source/browse/phpws/demo_ssl.php which is another websocket implementation in PHP. From the look of how they do it, it seems easy to add ssl-support to Ratchet.
Do you have any pointers on where and how to start? I would consider forking Ratchet and creating a pull-request after implementing support for SSL if you are interested.

IPBlackList

Import the IpBlackList from the RatchetApps repo into Ratchet.

Component rename

@oberstet With your permission, I would like to rename the Ratchet component WAMPServerComponent to AutobahnServerComponent. I know WAMP is the architecture of the protocol and Autobahn is your application. I wonder if you'd be ok for Ratchet being the PHP Autobahn?

The acronym WAMP in the PHP community is commonly known as "Windows Apache MySQL PHP". I've had several inquirers and misunderstandings when I keep pushing people to use WAMP with Ratchet.

Stable dependencies

v0.2 blocking

When Symfony 2.1 is released (out of beta) update composer.json to use that. At this point all of Ratchet's dependancies will no longer require "minimum-stability": "dev" and v0.2 can be released.

guzzle/guzzle v2.5.0 requires ext-curl * -> no matching package found.

Hi,

I tried installing using the documented method and got "cboden/Ratchet dev-master requires symfony/http-foundation 2.1.* -> no matching package found.", same issue as #36.

However the solutions provided do not work for me, I get the following error:

Problem 1
    - guzzle/guzzle v2.5.0 requires ext-curl * -> no matching package found.
    - cboden/Ratchet dev-master requires guzzle/guzzle 2.5.* -> satisfiable by guzzle/guzzle v2.5.0.
    - Installation request for cboden/ratchet dev-master -> satisfiable by cboden/Ratchet dev-master.

Here is the content of my composer.json:

{
    "require": {
        "cboden/Ratchet": "dev-master"
    },
    "minimum-stability": "dev"
}

Concurrent connections

I wonder how many concurrent connections Ratchet can handle, since it relies on the Webserver (e.g. Apache) and its underlying and limited number of threads.
Does it mean if I have 100 threads the server would block any further connections?

Greets,
krnl

Guzzle version

Hi,

Would it be possible to update to latest guzzle version ? (currently 2.7.0)

Back up

Ratchet, the PHP component based WebSocket library is back on GitHub to stay!

This ticket was created to inform all the previous followers (that's you) of the re-upload.

Since Ratchet was temporarily taken down two months ago (over a contract concern, everything OK now) I've added support for read-only Symfony2 Sessions and begun transport with libevent - in their respective branches.

@mikealmond
@nrk
@igorw
@pminnieur
@oberstet
@jbroadway
@Kwattro
@rjsteinert

Remove commands; direct calls

Add send and close methods to the ConnectionInterface. The user will call these functions directly instead of having to create commands from different namespaces and return them from their function. Each component has the ability to create a new proxy connection object that will decorate the one given to it. These objects can change the functionality of send and close (WebSocket frame) or add new methods (WAMPs callResult, callError, publish).

Create Limiter component

Create a Limiter component that implements MessageComponentInterface that gives developers the ability to create limitations that can include:

  • Max number of connections
  • Max number of connections per client (IP based)
  • Byte limit per interval
  • Duration the connection can be open

Additionally, implement the WsServerInterface that can work with or without WsServer and provides the option to limit number of messages per interval if put on top of WsServer.

<?php
    $limiter = new Limiter(new App);

    $limiter
        ->maxConnections(10000)           // 10k connections
        ->maxConnectionsPerAddress(3)     // 3 connections per user
        ->maxDataPerInterval(1048576, 60) // 1MB per minute
        ->maxDuration(28800)              // Disconnect after 8 hours
    ;

    $server = IoServer::factory($limiter);
    $server->run();

Also, consider tying into IpBlackList. Perhaps have the ability for a developer to add an address to IpBlackList if one of the limitations have been reached.

Update to latest guzzle

The main issue really is that v2.0.2 is being required explicitly, which allows no other version to be used, not even from the 2.0 versions. If we're going to loosen this, we might as well upgrade to the latest version.

I tried to upgrade, but it requires some changes due to the way guzzle parses headers. Basically each header is now an array of values, eg.: [ "Connection": [ "Upgrade" ] ]

Hixie Sub-Protocol issues

AutobahnJS isn't working properly on Safari. The connection is being made but the client is not recognizing the connection. This is only happening when sub-protocols are being set.

The sub-protocol acceptance works differently from Hixie to HyBi (RFC) - I believe this has something to do with it.

Cannot install with ZMQ

I have successfully set up a server from this guide http://socketo.me/docs/push before, but now I was trying to fetch a fresh install of Ratchet + ZMQ , but I encountered the error:

Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Conclusion: don't install cboden/Ratchet v0.2.1
- Installation request for cboden/ratchet 0.2.* -> satisfiable by cboden/Ratchet v0.2.0, cboden/Ratchet v0.2.1.
- Conclusion: remove react/event-loop v0.2.1
- Conclusion: don't install react/react v0.1.1|keep react/event-loop v0.2.1
- Conclusion: don't install react/socket v0.1.0|keep react/event-loop v0.2.1
- react/zmq dev-master requires react/event-loop 0.2.* -> satisfiable by react/event-loop v0.2.1, react/event-loop v0.2.0, react/event-loop v0.2.1, react/react v0.2.0, react/react v0.2.1.
- react/zmq dev-master requires react/event-loop 0.2.* -> satisfiable by react/event-loop v0.2.1, react/event-loop v0.2.0, react/event-loop v0.2.1, react/react v0.2.0, react/react v0.2.1.
- Can only install one of: react/react v0.2.0, react/react v0.1.0.
- Can only install one of: react/react v0.2.1, react/react v0.1.0.
- don't install react/event-loop v0.2.0|don't install react/react v0.1.0
- don't install react/event-loop v0.2.1|don't install react/react v0.1.0
- cboden/Ratchet v0.2.0 requires react/socket 0.1.* -> satisfiable by react/react v0.1.0, react/react 0.1.1, react/socket v0.1.0, react/socket v0.1.1.
- Conclusion: don't install react/socket v0.1.1|keep react/event-loop v0.2.1
- Installation request for react/zmq dev-master -> satisfiable by react/zmq dev-master.

My composer.json is:

{ "minimum-stability" : "dev", "require": { "cboden/Ratchet": "0.2.*" , "react/zmq": "dev-master" } }

I can successfully install Ratchet package without ZMQ, and ZMQ without Ratchet. Both together, fails.

What is the problem and possible workaround?

Fix Sessions

A recent update to the Symfony master branch changed their Session API causing a BC break. The Ratchet Session Component needs to be updated accordingly.

New Transport

At the very least, finalize the interface for the Server I/O Component for v0.1.

Currently, there's a wrapper class for low level BSD sockets that is to be created, configured and sent to the I/O class by users (too confusing). The class should only require the port, optionally the IP address, and optionally a "transport" class. If none is specified, use libevent if able to.

This has been started in the libevent branch.

Finally, attempt to incorporate SocketServer via an adapter class. This will enable Ratchet to focus more on WebSocket application development and less on I/O. /cc @igorw

Also, come up with a better name than "Transport" ;)

Chat Demo Crashes Safari and Chrome on iOS

Both have websocket support and I have successfully used websockets on these browsers before. Not sure if it is underlying Rat het problem or just a problem with demo.

Frame data caching

Create a data-caching class to be used with protocol frame methods. The same payload sent to multiple clients should not go through the process of being framed multiple times.

Binary support

Part of #13 is including binary message support for the WS protocol.

I'm thinking this will expand on the WebSocketComponent interface addax an onFile method. Try to further incorporate SF2 HttpFoundation by passing a File object to the method.

Refactor WebSocket code

Starting with moving much of the WsServer::onOpen code into two separate classes:

  • One for buffering headers, handling the initial handshake, and upgrading the protocol
  • The other for handling fragmentation of messages and dealing with control frames

Malformed UTF-8 characters, possibly incorrectly encoded

We have been testing the server for some time now and just got the Malformed UTF-8 characters, possibly incorrectly encoded error.
Only 1 client had it and he used Chrome like allot of the other test clients we used.
Is there anything i can do about this ?

Further more all the test clients use AuthoBahnJS to send the data to the server

Stack trace:
#0 /websocket/vendor/cboden/Ratchet/src/Ratchet/WebSocket/Version/Hixie76.php(85): Ratchet\Wamp\ServerProtocol->onMessage(Object(Ratchet\WebSocket\Version\Hixie76\Connection), '[7,"dannyb",{"t...')
#1 /websocket/vendor/cboden/Ratchet/src/Ratchet/WebSocket/WsServer.php(130): Ratchet\WebSocket\Version\Hixie76->onMessage(Object(Ratchet\WebSocket\Version\Hixie76\Connection), '?[7,"dannyb",{"...')
#2 /websocket/vendor/cboden/Ratchet/src/Ratchet/Server/IoServer.php(103): Ratchet\WebSocket\WsServer->onMessage(Object(Ratchet\Server\IoConnection), '?[7,"dannyb",{"...')
#3 [internal function]: Ratchet\Server\IoServer->handleData('?[7,"dannyb",{"...', Object(React\Socket\Connection))
#4 /websocket/vendor/evenement/evenement/src/Evenement/EventEmitter.php(70): call_user_func_array(Array, Array)
#5 /websocket/vendor/react/socket/React/Socket/Connection.php(20): Evenement\EventEmitter->emit('data', Array)
#6 [internal function]: React\Socket\Connection->handleData(Resource id #597, Object(React\EventLoop\StreamSelectLoop))
#7 /websocket/vendor/react/event-loop/React/EventLoop/StreamSelectLoop.php(128): call_user_func(Array, Resource id #597, Object(React\EventLoop\StreamSelectLoop))
#8 /websocket/vendor/react/event-loop/React/EventLoop/StreamSelectLoop.php(152): React\EventLoop\StreamSelectLoop->runStreamSelect()
#9 /websocket/vendor/react/event-loop/React/EventLoop/StreamSelectLoop.php(162): React\EventLoop\StreamSelectLoop->tick()
#10 /websocket/vendor/cboden/Ratchet/src/Ratchet/Server/IoServer.php(76): React\EventLoop\StreamSelectLoop->run()
#11 /websocket/proConnect.php(485): Ratchet\Server\IoServer->run()
#12 {main}Errorexception 'Ratchet\Wamp\JsonException' with message 'Malformed UTF-8 characters, possibly incorrectly encoded' in /websocket/vendor/cboden/Ratchet/src/Ratchet/Wamp/ServerProtocol.php:89

PHP Fatal error: Can't inherit abstract function React\Stream\WritableStreamInterface::close()

Hi -
I'm trying to run the chat application that is shown as an example. I'm able to the start the chat server. However, when I connect from a browser (using the javascript code given in the example), I get the following error.
Appreciate any help.
Thanks,
PC

php chat-server.php

PHP Fatal error: Can't inherit abstract function React\Stream\WritableStreamInterface::close() (previously declared abstract in React\Stream\ReadableStreamInterface) in /var/www/html/Symfony/vendor/react/stream/React/Stream/Stream.php on line 9
PHP Stack trace:
PHP 1. {main}() /var/www/html/Symfony/src/WebSockets/chat-server.php:0
PHP 2. Ratchet\Server\IoServer->run() /var/www/html/Symfony/src/WebSockets/chat-server.php:11
PHP 3. React\EventLoop\StreamSelectLoop->run() /var/www/html/Symfony/vendor/cboden/Ratchet/src/Ratchet/Server/IoServer.php:60
PHP 4. React\EventLoop\StreamSelectLoop->tick() /var/www/html/Symfony/vendor/react/event-loop/React/EventLoop/StreamSelectLoop.php:162
PHP 5. React\EventLoop\StreamSelectLoop->runStreamSelect() /var/www/html/Symfony/vendor/react/event-loop/React/EventLoop/StreamSelectLoop.php:152
PHP 6. call_user_func() /var/www/html/Symfony/vendor/react/event-loop/React/EventLoop/StreamSelectLoop.php:128
PHP 7. React\Socket{closure}() /var/www/html/Symfony/vendor/react/event-loop/React/EventLoop/StreamSelectLoop.php:128
PHP 8. React\Socket\Server->handleConnection() /var/www/html/Symfony/vendor/react/socket/React/Socket/Server.php:36
PHP 9. React\Socket\Server->createConnection() /var/www/html/Symfony/vendor/react/socket/React/Socket/Server.php:44
PHP 10. Composer\Autoload\ClassLoader->loadClass() /var/www/html/Symfony/vendor/react/socket/React/Socket/Server.php:0
PHP 11. include() /var/www/html/Symfony/vendor/composer/ClassLoader.php:150
PHP 12. Composer\Autoload\ClassLoader->loadClass() /var/www/html/Symfony/vendor/composer/ClassLoader.php:0
PHP 13. include() /var/www/html/Symfony/vendor/composer/ClassLoader.php:150

A quick server example

Having trouble while testing the quick server example ? seems that after a refactoring there were not changes in the example, this one works:

// Run the server application through the WebSocket protocol on port 8000
$server = \Ratchet\Server\IoServer::factory(new \Ratchet\WebSocket\WsServer(new Chat), 8000);
$server->run();

Greetings.

Routing

Attempt to incorporate Symfony2 Routing into WebSockets. This will allow users to support multiple applications on one instance of Ratchet.

Important routing parameters include:

  • path to route
  • controller - typehint of a Ratchet interface
  • allowed origins - whitelist, if nothing given, open to all

Thought: WebSocket::__construct can accept a RouteCollection or Ratchet MessageInterface to keep BC. If it's a Ratchet interface all paths are accepted and passed on. If a RouteCollection is passed connections are closed if the path is not matched.

Edit1: Removed subprotocols from parameter list: Subprotocols are functional, should continue to be implemented by interfaces
Edit2: A large part of this work will also have to include decoupling HTTP request handling from WebSocket connection upgrading

docs/push example contains two bugs

I was having trouble getting the docs/push example to work, and I was getting a fatal error:
'Failed to send message: Operation cannot be accomplished in current state'
when sending the second push message.

The fix for this was changing this line:
$socket = $context->getSocket(ZMQ::SOCKET_REQ, 'my pusher');
to this:
$socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'my pusher');

Also, there is an extra comma in this line:
public function onPublish(ConnectionInterface, $conn, $topic, $event) {
it should only be:
public function onPublish(ConnectionInterface $conn, $topic, $event) {

cheers,
dewey

Browser concatenation

If client messages are sent at close to the same time the browser is concatenating them together and sending as one message over the wire. FrameInterface and MessageInterfaceneed a getBufferOverflow method to add to the next frame/message.

Encoding

  • Use mb_check_encoding to make sure all messages receiving form a WebSocket client are UTF-8
  • Use mb_strlen($var, '8bit') when checking the byte length of a buffering frame as mbstring.func_overload could return "1" for a unicode character when expecting "3"
  • Add ext/mbstring as a requirement in composer.json

Cannot install via composer

Hi !

Since Friday I cannot install Ratchet using composer ... there is a 404 error while trying to get Symfony HttpFoundation 2.1.3

Thanks

Stateful Messages

Thinking: Update WebSocket MessageInterface's to use a state pattern. Depending on the state the Message will only accept one type of input (binary or ascii) and either state can output both binary and ascii. This will clean up the frame method on the main version classes and make implementing a client easier.

Naming convention

Redundant class names are redundant.

Finalize component names:

  • IOServerComponent -> IoServer (maybe just Io)
  • IpBlackListComponent -> IpBlackList
  • WebSocketComponent -> WsServer
  • SessionComponent -> SessionProvider
  • WAMPServerComponent -> WampServer
  • FlashPolicyComponent -> FlashPolicy

Website documentation can distinguish which classes are meant for the user to interact with and which are libraries used by components internally.

[Chrome 21.0.1180.89] "Invalid UTF-8 sequence in header value" during connection

Request headers:

Connection:Upgrade
Host:xxx.com:8000
Origin:http://xxx.com
Sec-WebSocket-Extensions:x-webkit-deflate-frame
Sec-WebSocket-Key:xzbEt3bITrFESU7HalvBuA==
Sec-WebSocket-Protocol:undefined
Sec-WebSocket-Version:13
Upgrade:websocket

Response:

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: ObavZ/AXO40kzmsLvYgoheBzhXY=
X-Powered-By: Ratchet/0.2
Sec-WebSocket-Protocol:

That's not an issue, please remove it

Hi, I know that you're very involved with symfony, but please do not assume that everybody on the earth loves the composer ( which is great, but that's not what I'm talking about ).

In your Ratchet's Read me, with the "A quick server example" section, you force the reader to use composer, which to my opinion is not a good thing. Thanks for your component, I'll use it anyway, but I think you should consider rewriting the read me example in a manner that a simple copy paste is enough to make the code works. By the way maybe I'm totally wrong but that's what I felt when I discover the Ratchet component. That said, let's use Ratchet !

Edit:
Oh, I just installed Ratched via composer and saw lot of dependencies, so the composer seems a good choice. Please remove my comment.

Closure based usage

Create a new facade class using Evenement to create a closure (node-like) based interface for a simpler way for users to create a Ratchet application.

<?php
$clients = new SplObjectStorage();

$ws = new Ratchet\Component\WebSocket\EventServer();

$ws->on('connect', function ($conn) use ($clients) {
    $clients->attach($conn);

    $conn->on('message', function ($message) use ($conn, $clients) {
        foreach ($clients as $client) {
            if ($conn !== $client) {
                $client->send($message);
            }
        }
    });

    $conn->on('close', function () use ($conn, $clients) {
        $clients->detach($conn);
    });

    $conn->on('error', function () use ($conn) {
        $conn->close();
    });
});

$ws->run(9001);

The trick, I think, will be incorporating fanning events such as those provided by WAMP

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.