Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xp-forge/websockets
WebSockets for the XP Framework
https://github.com/xp-forge/websockets
rfc6455 server websockets xp-framework
Last synced: 13 days ago
JSON representation
WebSockets for the XP Framework
- Host: GitHub
- URL: https://github.com/xp-forge/websockets
- Owner: xp-forge
- Created: 2019-09-23T09:45:06.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-24T13:38:47.000Z (8 months ago)
- Last Synced: 2024-04-24T19:47:46.440Z (7 months ago)
- Topics: rfc6455, server, websockets, xp-framework
- Language: PHP
- Size: 90.8 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
Awesome Lists containing this project
README
WebSockets for the XP Framework
========================================================================[![Build status on GitHub](https://github.com/xp-forge/websockets/workflows/Tests/badge.svg)](https://github.com/xp-forge/websockets/actions)
[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)
[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)
[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)
[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)
[![Latest Stable Version](https://poser.pugx.org/xp-forge/websockets/version.svg)](https://packagist.org/packages/xp-forge/websockets)Example
-------```php
use websocket\Listeners;class Imitator extends Listeners {
public function serve($events) {
return [
'/echo' => function($conn, $payload) {
$conn->send('You said: '.$payload);
}
];
}
}
```Run it using:
```bash
$ xp -supervise ws Imitator
@peer.ServerSocket(Resource id #138 -> tcp://0.0.0.0:8081))
Serving Imitator(dev)[] > websocket.logging.ToConsole
# ...
```To connect to this server, use the following:
```php
use util\cmd\Console;
use websocket\WebSocket;$s= new WebSocket('ws://localhost:8081/echo';
$s->connect();$s->send('Hello');
Console::writeLine('<<< ', $s->receive());
```On the JavaScript side, open the connection as follows:
```javascript
var ws = new WebSocket('ws://localhost:8081/echo');
ws.onmessage = (event) => console.log(event.data);ws.send('Hello'); // Will log "You said: Hello" to the console
```See also
--------* [WebSocket chat based on Redis queues](https://gist.github.com/thekid/7f11a62e0a57d18588694f058ebcc38a)
* [OpenAI Realtime API](https://platform.openai.com/docs/guides/realtime)