<small id='8P7y0'></small><noframes id='8P7y0'>

    <i id='8P7y0'><tr id='8P7y0'><dt id='8P7y0'><q id='8P7y0'><span id='8P7y0'><b id='8P7y0'><form id='8P7y0'><ins id='8P7y0'></ins><ul id='8P7y0'></ul><sub id='8P7y0'></sub></form><legend id='8P7y0'></legend><bdo id='8P7y0'><pre id='8P7y0'><center id='8P7y0'></center></pre></bdo></b><th id='8P7y0'></th></span></q></dt></tr></i><div id='8P7y0'><tfoot id='8P7y0'></tfoot><dl id='8P7y0'><fieldset id='8P7y0'></fieldset></dl></div>
  1. <legend id='8P7y0'><style id='8P7y0'><dir id='8P7y0'><q id='8P7y0'></q></dir></style></legend>

        <bdo id='8P7y0'></bdo><ul id='8P7y0'></ul>

      <tfoot id='8P7y0'></tfoot>

    1. 如何在 Symfony2 中正确使用 webSockets

      时间:2023-09-25
      <i id='oGYTK'><tr id='oGYTK'><dt id='oGYTK'><q id='oGYTK'><span id='oGYTK'><b id='oGYTK'><form id='oGYTK'><ins id='oGYTK'></ins><ul id='oGYTK'></ul><sub id='oGYTK'></sub></form><legend id='oGYTK'></legend><bdo id='oGYTK'><pre id='oGYTK'><center id='oGYTK'></center></pre></bdo></b><th id='oGYTK'></th></span></q></dt></tr></i><div id='oGYTK'><tfoot id='oGYTK'></tfoot><dl id='oGYTK'><fieldset id='oGYTK'></fieldset></dl></div>
    2. <tfoot id='oGYTK'></tfoot>

          <tbody id='oGYTK'></tbody>
            • <bdo id='oGYTK'></bdo><ul id='oGYTK'></ul>
              <legend id='oGYTK'><style id='oGYTK'><dir id='oGYTK'><q id='oGYTK'></q></dir></style></legend>
            • <small id='oGYTK'></small><noframes id='oGYTK'>

                本文介绍了如何在 Symfony2 中正确使用 webSockets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试在 Symfony2 中实现 websockets,

                I'm trying to implement websockets in Symfony2,

                我发现这个 http://socketo.me/ 看起来不错.

                I found this http://socketo.me/ which seems pretty good.

                我在 Symfony 中尝试了它并且它有效,这只是使用 telnet 的一个简单调用.但我不知道如何将其集成到 Symfony 中.

                I try it out of Symfony and it works, this was just a simple call using telnet. But I don't know how to integrate this in Symfony.

                我想我必须创建一个服务,但我真的不知道哪种服务以及如何从客户端调用它

                I think I have to create a service but I don't know realy which kind of service and how to call it from the client

                感谢您的帮助.

                推荐答案

                首先你应该创建一个服务.如果您想注入实体管理器和其他依赖项,请在此处进行.

                First you should create a service. If you want to inject your entity manager and other dependencies, do it there.

                在 src/MyApp/MyBundle/Resources/config/services.yml 中:

                In src/MyApp/MyBundle/Resources/config/services.yml:

                services:
                    chat:
                        class: MyAppMyBundleChat
                        arguments: 
                            - @doctrine.orm.default_entity_manager
                

                在 src/MyApp/MyBundle/Chat.php 中:

                And in src/MyApp/MyBundle/Chat.php:

                class Chat implements MessageComponentInterface {
                    /**
                     * @var DoctrineORMEntityManager
                     */
                    protected $em;
                    /**
                     * Constructor
                     *
                     * @param DoctrineORMEntityManager $em
                     */
                    public function __construct($em)
                    {
                        $this->em = $em;
                    }
                    // onOpen, onMessage, onClose, onError ...
                

                接下来,执行控制台命令来运行服务器.

                Next, make a console command to run the server.

                在 src/MyApp/MyBundle/Command/ServerCommand.php 中

                In src/MyApp/MyBundle/Command/ServerCommand.php

                use SymfonyBundleFrameworkBundleCommandContainerAwareCommand;
                use SymfonyComponentConsoleInputInputInterface;
                use SymfonyComponentConsoleOutputOutputInterface;
                use RatchetServerIoServer;
                
                class ServerCommand extends ContainerAwareCommand
                {
                    protected function configure()
                    {
                        $this
                            ->setName('chat:server')
                            ->setDescription('Start the Chat server');
                    }
                
                    protected function execute(InputInterface $input, OutputInterface $output)
                    {
                        $chat = $this->getContainer()->get('chat');
                        $server = IoServer::factory($chat, 8080);
                        $server->run();
                    }
                }
                

                现在您有一个带有依赖注入的 Chat 类,您可以将服务器作为控制台命令运行.希望这会有所帮助!

                Now you have a Chat class with dependency injections, and you can run the server as a console command. Hope this helps!

                这篇关于如何在 Symfony2 中正确使用 webSockets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:刷新有关数据库更新的网页 下一篇:laravel 5 中的简单 websocket 实现

                相关文章

                最新文章

                <legend id='QEjj4'><style id='QEjj4'><dir id='QEjj4'><q id='QEjj4'></q></dir></style></legend>

                  <bdo id='QEjj4'></bdo><ul id='QEjj4'></ul>

                  <small id='QEjj4'></small><noframes id='QEjj4'>

                  1. <tfoot id='QEjj4'></tfoot>

                    <i id='QEjj4'><tr id='QEjj4'><dt id='QEjj4'><q id='QEjj4'><span id='QEjj4'><b id='QEjj4'><form id='QEjj4'><ins id='QEjj4'></ins><ul id='QEjj4'></ul><sub id='QEjj4'></sub></form><legend id='QEjj4'></legend><bdo id='QEjj4'><pre id='QEjj4'><center id='QEjj4'></center></pre></bdo></b><th id='QEjj4'></th></span></q></dt></tr></i><div id='QEjj4'><tfoot id='QEjj4'></tfoot><dl id='QEjj4'><fieldset id='QEjj4'></fieldset></dl></div>