Comments (3)
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.
I'm sorry I didn't understand you well...
I'll describe my problem in detail once again.
I use:
- Windows 10x64;
- OpenSrver. https://ospanel.io / (analog of XAMPP);
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 folderc:\openserver\domains \
;
Result:c:\openserver\domains\phpWssArthurkushmanGithub2 \
; - I manually copied the
src
folder to thec:\openserver\domains\phpWssArthurkushmanGithub2 \
;
The folder containsc:\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?
from php-wss.
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)
- Proxy Connection Problem HOT 8
- Insufficient buffer size for HTTP collateral HOT 1
- Opcode check inaccuracy
- SSL Support HOT 6
- Refactor variables/naming with underscore artefacts
- Adopt to php7.4-8.0 transition next to 2.0 major release
- Bug $isMasked is always true
- Bug: unsaved large frame payload and closed connection (on server) HOT 3
- stream_socket_accept(): Accept failed: Operation timed out HOT 1
- Websocket limits Timeout and Clients per Fork HOT 5
- Not an Issue. Rather a question about an application HOT 1
- The package name composer require arthurkushman/php-wss is invalid, HOT 1
- Trying to access array offset on value of type bool HOT 3
- PHP Fatal error: Uncaught WSSC\Exceptions\ConnectionException: Could not open socket to "localhost:8888": (0). HOT 1
- stream_socket_enable_crypto(): SSL: Handshake timed out - high CPU usage HOT 5
- "PHP Warning: stream_select(): You MUST recompile PHP with a larger value of FD_SETSIZE" HOT 2
- Invalid server upgrade response and bad opcode HOT 1
- How client checks if any new messages available to receive?
- HTTP/1.1 301 Moved Permanently HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-wss.