久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

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

    • <bdo id='kzv7Y'></bdo><ul id='kzv7Y'></ul>

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

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

      laravel 5 中的簡單 websocket 實現

      Simple websocket implementation in laravel 5(laravel 5 中的簡單 websocket 實現)
      • <bdo id='JFtyB'></bdo><ul id='JFtyB'></ul>
          <tbody id='JFtyB'></tbody>
      • <i id='JFtyB'><tr id='JFtyB'><dt id='JFtyB'><q id='JFtyB'><span id='JFtyB'><b id='JFtyB'><form id='JFtyB'><ins id='JFtyB'></ins><ul id='JFtyB'></ul><sub id='JFtyB'></sub></form><legend id='JFtyB'></legend><bdo id='JFtyB'><pre id='JFtyB'><center id='JFtyB'></center></pre></bdo></b><th id='JFtyB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='JFtyB'><tfoot id='JFtyB'></tfoot><dl id='JFtyB'><fieldset id='JFtyB'></fieldset></dl></div>
        <legend id='JFtyB'><style id='JFtyB'><dir id='JFtyB'><q id='JFtyB'></q></dir></style></legend>
              <tfoot id='JFtyB'></tfoot>

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

                本文介紹了laravel 5 中的簡單 websocket 實現的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我需要在 Laravel 中實現非常簡單和非常基本的 websocket,以在作為客戶端的 phonegap 應用程序和作為服務器的 Laravel 網站之間實現數據同步過程.我跟著這個教程http://www.binarytides.com/websockets-php-tutorial/ 來實現和測試 websocket,它可以工作.像這個我需要非常簡單的 Laravel 實現,我可以在其中從 js 客戶端調用我的控制器方法.客戶端將是我的 phonegap 應用程序.我在 laravel 中找到了一些帶有教程的 websocket 包,但我發現很難實現它們.沒有人與控制器進行交互,他們在各處監聽事件并創建類,但不在控制器中.我已經在 Controller 中編寫了所有邏輯并使用 ajax 請求對其進行了測試,但現在我將通過 websocket 實現它,因為我需要雙向通信來實現同步過程.我是 Laravel 的新手,所以請給我一些幫助.如果有人能告訴我如何在laravel中集成about教程,以便客戶端可以直接調用控制器發送數據,那就太好了.

                I need to implement very simple and very basic websocket in Laravel to implement data synchronization process between my phonegap app as client and my Laravel Website as server. I followed this tutorial http://www.binarytides.com/websockets-php-tutorial/ to implement and test websocket and it works. Like this one i need very simple laravel implementation where i can call my controller method from js client. Client will be my phonegap application. I found some packages for websocket in laravel with tutorials, but i found difficult to implement them. No one was interacting with controllers, they were listening to events and creating classes here and there but not in controllers. I have written all my logic in Controller and tested it with ajax request but now i will implement it by websocket because i need bidirectional communication to implement Synchronization process. I am new to Laravel so please provide me some help. Also it will be so great if somebody can tell me how to integrate the about tutorial in laravel to so that client can directly call controller to send data.

                推薦答案

                我最終使用了brainboxlabs的brainsocket (https://github.com/BrainBoxLabs/brain-socket) .正如它的文檔所說,它的 laravel 4 包但它也可以與 laravel 5 一起使用,沒有任何問題.

                I ended up using brainboxlabs's brainsocket (https://github.com/BrainBoxLabs/brain-socket) . As its document says its laravel 4 package but it also works with laravel 5 without any issue.

                要使用 laravel 5 安裝此包.請按照上述 github 鏈接上的文檔進行操作.它說在應用程序文件夾中創建一個 event.php 文件和一些與事件相關的代碼.而不是這一步,只需在 app/Providers/EventServiceProvider.php 文件中添加與事件相關的代碼.在其引導方法中,添加該代碼

                To install this package with laravel 5. Follow the documentation on the above github link. Where it says to create an event.php file in app folder and some events related code. Instead of this step simply add that event related code in app/Providers/EventServiceProvider.php file. In its boot method, add that code which is

                Event::listen('generic.event',function($client_data){
                    return BrainSocket::message('generic.event',array('message'=>'A message from a generic event fired in Laravel!'));
                });
                
                Event::listen('app.success',function($client_data){
                    return BrainSocket::success(array('There was a Laravel App Success Event!'));
                });
                
                Event::listen('app.error',function($client_data){
                    return BrainSocket::error(array('There was a Laravel App Error!'));
                });
                

                在這一步之后還有一步添加

                After this step there was a step of adding

                require app_path().'/filters.php';
                require app_path().'/events.php';
                

                在 app/start/global.php 中.你可以把這一步留給 Laravel 5.

                in app/start/global.php . You can leave this step for laravel 5.

                好的,Web 套接字已經實現.您可以通過運行命令 artisan brainsocket:start 使用 cmd 啟動 websocket 服務器進行測試.你可以選擇為它提供 port artisan Brainsocket:start 9000

                Ok so Web socket has been implemented. You can test by starting the websocket server using cmd by running the command artisan brainsocket:start. You can optionally provide it the port artisan brainsocket:start 9000

                另一個要求是調用控制器來執行其余的任務.為此,我直接編輯到提供程序包中.我不推薦這樣做,因為這不是一個好方法.當您使用 Composer 更新您的包時,您的更改將丟失.所以你必須找到更好的選擇.但它只是一行更改.

                Another requirement was to call controller to to perform rest of the task. For this i directly edited into to provider package. I do not recommend this as it is not a good way. When you will update your package using composer your changes will be lost. So you have to find a better option. But its just a one line change.

                在 vendorrainboxlabsrain-socketsrcBrainSocketBrainSocketServer.php 中,我編輯了方法start"中的代碼并替換

                In vendorrainboxlabsrain-socketsrcBrainSocketBrainSocketServer.php i edited code in method "start" and replace

                $this->server = IoServer::factory(
                            new HttpServer(
                                new WsServer(
                                    new BrainSocketEventListener(
                                        new BrainSocketResponse(new LaravelEventPublisher())
                                    )
                                )
                            )
                            , $port
                        );
                

                $this->server = IoServer::factory(
                            new HttpServer(
                                new WsServer(
                               new FMISHttpControllersSynchronizationController(
                                  new BrainSocketResponse(new LaravelEventPublisher())
                                                            )
                                )
                            )
                            , $port
                        );
                

                在我的 SynchronizationController 文件中.

                And in my SynchronizationController file.

                我在上面添加了這個

                use RatchetMessageComponentInterface;
                use RatchetConnectionInterface;
                use BrainSocketBrainSocketResponseInterface;
                

                實現的界面是這樣的.

                class SynchronizationController extends Controller implements MessageComponentInterface{
                

                并實現了該接口的方法.

                and implemented the methods of this interface.

                public function __construct(BrainSocketResponseInterface $response) {
                        $this->clients = new SplObjectStorage;
                        $this->response = $response;
                }
                
                public function onOpen(ConnectionInterface $conn) {
                        echo "Connection Established! 
                ";
                }
                
                
                public function onMessage(ConnectionInterface $conn, $msg){
                 echo "this messge gets called whenever there is a messge sent from js client";
                }
                
                public function onClose(ConnectionInterface $conn) {
                    echo "Connection {$conn->resourceId} has disconnected
                ";
                }
                
                public function onError(ConnectionInterface $conn, Exception $e) {
                        $msg = "An error has occurred: {$e->getMessage()}
                ";
                        echo $msg;
                        $conn->close();
                }
                

                您必須更改這些方法才能實現您的功能.在此之后,您可以從您的 js 客戶端調用.你也不需要使用它的 js 庫.您只需使用本教程中描述的 js 客戶端發送數據 http://www.binarytides.com/websockets-php-tutorial/ .

                You have to change in these methods to implement your functionality. After this you can call from your js client. And you are not required to use its js library as well. You simply send data using js client describe in this tutorial http://www.binarytides.com/websockets-php-tutorial/ .

                如果有人需要有關其實施的更多幫助,請告訴我.

                Let me know if somebody need any more help regarding its implementation.

                這篇關于laravel 5 中的簡單 websocket 實現的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                PHP PDO ODBC connection(PHP PDO ODBC 連接)
                Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                  <legend id='aWqSx'><style id='aWqSx'><dir id='aWqSx'><q id='aWqSx'></q></dir></style></legend>
                • <tfoot id='aWqSx'></tfoot>
                    <tbody id='aWqSx'></tbody>

                  1. <small id='aWqSx'></small><noframes id='aWqSx'>

                          <bdo id='aWqSx'></bdo><ul id='aWqSx'></ul>
                          <i id='aWqSx'><tr id='aWqSx'><dt id='aWqSx'><q id='aWqSx'><span id='aWqSx'><b id='aWqSx'><form id='aWqSx'><ins id='aWqSx'></ins><ul id='aWqSx'></ul><sub id='aWqSx'></sub></form><legend id='aWqSx'></legend><bdo id='aWqSx'><pre id='aWqSx'><center id='aWqSx'></center></pre></bdo></b><th id='aWqSx'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='aWqSx'><tfoot id='aWqSx'></tfoot><dl id='aWqSx'><fieldset id='aWqSx'></fieldset></dl></div>
                          主站蜘蛛池模板: 国产欧美一区二区三区日本久久久 | 蜜月va乱码一区二区三区 | 围产精品久久久久久久 | 日韩视频精品在线 | 日韩精品久久 | 国产一区二区在线播放 | 成人黄色电影免费 | 国内毛片毛片毛片毛片 | 国产91亚洲精品一区二区三区 | 国产精品久久久久久久久久久新郎 | 久久久91精品国产一区二区三区 | 日日夜夜草 | 高清久久久| 国产精品美女久久久久久免费 | 羞羞免费网站 | 国产精品成人一区二区三区 | 欧美一区不卡 | 亚洲精品一区中文字幕乱码 | 亚洲国产视频一区二区 | 女同久久另类99精品国产 | av喷水| 亚洲福利 | 欧美日韩精品一区 | 久久av一区二区三区 | 狠狠操狠狠操 | 亚洲精品久久久久久久久久久 | 91精品国产美女在线观看 | 国产中文字幕在线 | 夜久久 | 中文字幕精品一区二区三区在线 | 日韩 欧美 二区 | 欧美一区二区免费 | 少妇精品亚洲一区二区成人 | 福利视频一二区 | 欧美精品中文 | 四虎首页 | 亚洲国产一区二区三区在线观看 | 日韩精品一区在线 | 欧美色综合一区二区三区 | com.色.www在线观看 | 亚洲成人av在线 |