PHP code example of bordeux / websocket-bundle

1. Go to this page and download the library: Download bordeux/websocket-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bordeux / websocket-bundle example snippets


    public function registerBundles()
    {
        $bundles = array(
			...
            new Bordeux\WebsocketBundle\BordeuxWebsocketBundle(),
			....
        );

        return $bundles;
    }




/**
 * File must be on <your-boundle>/Websocket/<your-name>Websocket.php
 */

namespace Tattool\Bundle\MessagesBundle\Websocket;

use Bordeux\WebsocketBundle\Websocket\Client;
use Bordeux\WebsocketBundle\Websocket\Message;
use Bordeux\WebsocketBundle\Websocket\Websocket;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

/**
 * Class SimpleWebsocket
 * @author Krzysztof Bednarczyk
 * @package Tattool\Bundle\MessagesBundle\Websocket
 */
class SimpleWebsocket extends Websocket
{


    /**
     * @author Krzysztof Bednarczyk
     * @param RouteCollection $collection
     */
    public function configureRoutes(RouteCollection $collection)
    {
        $collection->add("user.messages", new Route(
            "/ws/user/messages/{id}/{accessToken}/", [
            //defaults
        ], [
                "id" => "\d+", //arczyk
     * @param Client $client
     * @return void
     */
    public function onError(Client $client)
    {
        $client->kill(); //kill client ;)
    }

    /**
     * @author Krzysztof Bednarczyk
     * @param Client $client
     * @param Message $message
     * @return void
     */
    public function onMessage(Client $client, Message $message)
    {

        $client->sendMessage(new Message(
            "Hello World!"
        ));
    }

    /**
     * @author Krzysztof Bednarczyk
     * @param Client $client
     * @return void
     */
    public function onDisconnect(Client $client)
    {
    }

    /**
     * @author Krzysztof Bednarczyk
     * @return mixed
     */
    public function run()
    {
        //executed after initialize controller

        $this->getLoop(); //loop factor for async

        $this->getContainer(); //container

        $this->getParameter("doctrine.class"); //symfony parameters

        $this->getDoctrine(); //doctrine
    }

}