PHP code example of francium / diffsocket

1. Go to this page and download the library: Download francium/diffsocket 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/ */

    

francium / diffsocket example snippets


  
  $DS = new Fr\DiffSocket(array(
    "server" => array(
      "host" => "127.0.0.1",
      "port" => "8000"
    )
  ));
  

  namespace Fr\DiffSocket\Service;

  use Ratchet\MessageComponentInterface;
  use Ratchet\ConnectionInterface;

  class SayHello implements MessageComponentInterface {

    public function onOpen(ConnectionInterface $conn){
      echo "New Connection - " . $conn->resourceId;
    }

    public function onClose(ConnectionInterface $conn){}
    public function onError(ConnectionInterface $conn, $error){}

    public function onMessage(ConnectionInterface $conn, $message){
      $conn->send("Hello");
    }

  }
  

  $DS->addService("say-hello", "path/to/SayHello.php");
  

  $DS->run();
  

$DS = new Fr\DiffSocket(array(
  "server" => array(
    "host" => "127.0.0.1",
    "port" => "8000"
  ),
  "services" => array(
    "say-hello" => __DIR__ . "/services/SayHello.php",
    "chat" => __DIR__ . "/services/Chat.php",
    "game" => __DIR__ . "/services/GameServer.php"
  )
));