Giter Site home page Giter Site logo

How to install a socket server about php-wss HOT 3 CLOSED

it19862 avatar it19862 commented on June 7, 2024
How to install a socket server

from php-wss.

Comments (3)

arthurkushman avatar arthurkushman commented on June 7, 2024

You need to create a file just like described in readme.md ex.:

<?php
use WSSC\Contracts\ConnectionContract;
use WSSC\Contracts\WebSocket;
use WSSC\Exceptions\WebSocketException;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

class ServerHandler extends WebSocket
{

    /*
     *  if You need to parse URI context like /messanger/chat/JKN324jn4213
     *  You can do so by placing URI parts into an array - $pathParams, when Socket will receive a connection
     *  this variable will be appropriately set to key => value pairs, ex.: ':context' => 'chat'
     *  Otherwise leave $pathParams as an empty array
     */

    public $pathParams = [':entity', ':context', ':token'];
    private $clients = [];

    private $log;

    /**
     * ServerHandler constructor.
     *
     * @throws \Exception
     */
    public function __construct()
    {
        // create a log channel
        $this->log = new Logger('ServerSocket');
        $this->log->pushHandler(new StreamHandler('./tests/tests.log'));
    }

    public function onOpen(ConnectionContract $conn)
    {
        $this->clients[$conn->getUniqueSocketId()] = $conn;
        $this->log->debug('Connection opend, total clients: ' . count($this->clients));
    }

    public function onMessage(ConnectionContract $recv, $msg)
    {
        $this->log->debug('Received message:  ' . $msg);
        $recv->send($msg);
    }

    public function onClose(ConnectionContract $conn)
    {
        unset($this->clients[$conn->getUniqueSocketId()]);
        $this->log->debug('close: ' . print_r($this->clients, 1));
        $conn->close();
    }

    /**
     * @param ConnectionContract $conn
     * @param WebSocketException $ex
     */
    public function onError(ConnectionContract $conn, WebSocketException $ex)
    {
        echo 'Error occured: ' . $ex->printStack();
    }

    /**
     * You may want to implement these methods to bring ping/pong events
     *
     * @param ConnectionContract $conn
     * @param string $msg
     */
    public function onPing(ConnectionContract $conn, $msg)
    {
        // TODO: Implement onPing() method.
    }

    /**
     * @param ConnectionContract $conn
     * @param $msg
     * @return mixed
     */
    public function onPong(ConnectionContract $conn, $msg)
    {
        // TODO: Implement onPong() method.
    }
}

And run it with php ServerHandler.php, don't forget to install php-wss with command composer require arthurkushman/php-wss, the project itself shouldn't be just downloaded manually, because u need autoload and other features.

from php-wss.

it19862 avatar it19862 commented on June 7, 2024

@arthurkushman

I'm sorry I didn't understand you well...
I'll describe my problem in detail once again.
I use:

I did:

  • I downloaded the archive manually https://github.com/arthurkushman/php-wss;
    • I unpacked the archive;
    • in OpenSrver I created a folder: phpWssArthurkushmanGithub2\ in the folder c:\openserver\domains \;
      Result: c:\openserver\domains\phpWssArthurkushmanGithub2 \;
    • I manually copied the src folder to the c:\openserver\domains\phpWssArthurkushmanGithub2 \;
      The folder contains c:\openserver\domains\phpWssArthurkushmanGithub2\src\
      Components
      Contracts
      Exceptions
      WebSocketClient.php
      WebSocketServer.php
    • I opened the OpenSrver console;
    • I entered the command: cd c:\openserver\domains\phpWssArthurkushmanGithub2\
    • I entered the command: composer require arthurkushman/php-wss
    • result: in the folder C:\OpenServer\domains\phpWssArthurkushmanGithub2 added folders and files
      src
      vendor
      composer.json
      composer.lock

Questions.
3. How to properly upload the php-wss project to your computer?
2. Where to place the file ServerHandler.php ?
3. If you run the file ServerHandler.php will the server work in the browser?
4. How to create a client? Where to locate the client? How to launch the client?

27 05 2022_23-12-51
27 05 2022_23-12-52
27 05 2022_23-12-56
27 05 2022_23-13-12
27 05 2022_23-15-04
27 05 2022_23-16-05
27 05 2022_23-16-23

from php-wss.

arthurkushman avatar arthurkushman commented on June 7, 2024

Please create discussions here - https://github.com/arthurkushman/php-wss/discussions, as this is not an issue with php-wss lib at all, it seems more like your personal problems with installation. This library works for 7 years since 2015 in all OSs and large companies. So there are lots of misunderstanding of how to use php and it's libraries - nothing to do with php-wss.

Closing this issue due to irrelevant questions in context of an issue tracking.

PS I don't have time to explain to everybody how to install packages and use them on every system.
Hope for understanding.

from php-wss.

Related Issues (20)

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.