ad3n / ratchet-bundle
Symfony 的 WebSocket 扩展包
v0.6
2020-06-09 06:22 UTC
Requires
- php: >=7.0
- cboden/ratchet: ^0.4
- symfony/config: ~3.0|~4.0|~5.0
- symfony/console: ~3.0|~4.0|~5.0
- symfony/dependency-injection: ~3.0|~4.0|~5.0
- symfony/framework-bundle: ~3.0|~4.0|~5.0
- symfony/http-kernel: ~3.0|~4.0|~5.0
This package is auto-updated.
Last update: 2024-08-29 23:28:27 UTC
README
安装
composer req ad3n/ratchet-bundle
激活 Bundle(可选)
在您的 AppKernel.php
中添加 new Ihsan\RatchetBundle\IhsanRatchetBundle()
创建您的消息处理器
<?php namespace YourBundle\Message\Processor; use Ihsan\RatchetBundle\Message\Message; use Ihsan\RatchetBundle\Processor\MessageProcessorInterface; use Ratchet\ConnectionInterface; /** * @author Muhamad Surya Iksanudin <surya.kejawen@gmail.com> */ class MyOwnMessageProcessor implements MessageProcessorInterface { /** * @param ConnectionInterface $connection * @param Message $message * * @return Message */ public function process(ConnectionInterface $connection, Message $message): Message { //$message is message send by the client //Your Own Logic return $message;//return original message or //return new Message(json_encode(['message' => 'Hello', 'more_data_to_expose' => $data])); } }
创建服务
您必须添加标签 ihsan_ratchet.message_processor
来注册您自己的消息处理器
YourBundle\Message\Processor\MyOwnMessageProcessor: tags: - { name: 'ihsan_ratchet.message_processor' }
添加配置键
WEB_SOCKET_PORT=7777
或者
ihsan_ratchet: web_socket_port: 7777
启动服务器
运行 php bin/console ihsan:server:start