https://github.com/xp-forge/websockets
WebSockets for the XP Framework
https://github.com/xp-forge/websockets
rfc6455 server websockets xp-framework
Last synced: 7 months 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 6 years ago)
- Default Branch: master
- Last Pushed: 2025-01-12T11:53:17.000Z (10 months ago)
- Last Synced: 2025-04-24T01:47:15.465Z (7 months ago)
- Topics: rfc6455, server, websockets, xp-framework
- Language: PHP
- Size: 114 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
Awesome Lists containing this project
README
WebSockets for the XP Framework
========================================================================
[](https://github.com/xp-forge/websockets/actions)
[](https://github.com/xp-framework/core)
[](https://github.com/xp-framework/core/blob/master/LICENCE.md)
[](http://php.net/)
[](http://php.net/)
[](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)