Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/diloabininyeri/socket

A library with socket channels where you can broadcast and manage channels, such as send a message to the bank channel and send a message to the software channel.
https://github.com/diloabininyeri/socket

broadcast channels client notification server server-client socket socket-io stream websockets

Last synced: about 3 hours ago
JSON representation

A library with socket channels where you can broadcast and manage channels, such as send a message to the bank channel and send a message to the software channel.

Awesome Lists containing this project

README

        

### Socket Channels

This is a socket library, it is an advanced library, the purpose of which is to subscribe to channels on the socket and send messages to channels, as well as leaving channels...

for install
```console
composer require zeus/pusher
```

### Socket Server Management
We manage the entire socket server with an object inherited from the AbstractSocketClientHandler object...
In the example below, it is the ClientHandler object, but this is entirely up to your wishes.
Let's, For example, let's send the message to everyone.

server.php
```php
use Zeus\Pusher\AbstractSocketClientHandler;
use Zeus\Pusher\SocketServer;

class ClientHandler extends AbstractSocketClientHandler
{

#[\Override]
public function run(): void
{
$this->sendTo()->everyone($this->getMessage());
}
}

$socketServer = new SocketServer(ClientHandler::class);
$socketServer->serve('127.0.0.1', 8080);

```
Run in the Terminal
```console
php server.php
```
js websocket code

```html

const socket = new WebSocket('ws://127.0.0.1:8080');

socket.addEventListener('open', (event) => {
console.log('WebSocket connection opened');
socket.send('test message');
});

socket.addEventListener('message', (event) => {
const message = event.data;
alert(`Received message: ${message}`);
});

socket.addEventListener('close', (event) => {
console.log('socket is closed', JSON.stringify(event));
});