pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="pkxgf7l" 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="lpofpz8" 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="tmmbe8x" id='aWqSx'><tfoot id='aWqSx'></tfoot><dl id='aWqSx'><fieldset id='aWqSx'></fieldset></dl></div>
                          主站蜘蛛池模板: 圣才学习网-考研考证学习平台,提供万种考研考证电子书、题库、视频课程等考试资料 | 天津云仓-天津仓储物流-天津云仓一件代发-顺东云仓 | 网站建设-高端品牌网站设计制作一站式定制_杭州APP/微信小程序开发运营-鼎易科技 | 真空搅拌机-行星搅拌机-双行星动力混合机-广州市番禺区源创化工设备厂 | 洗砂机械-球磨制砂机-洗沙制砂机械设备_青州冠诚重工机械有限公司 | 活性炭厂家-蜂窝活性炭-粉状/柱状/果壳/椰壳活性炭-大千净化-活性炭 | 酒吧霸屏软件_酒吧霸屏系统,酒吧微上墙,夜场霸屏软件,酒吧点歌软件,酒吧互动游戏,酒吧大屏幕软件系统下载 | 踏板力计,制动仪,非接触多功能速度仪,逆反射系数测试仪-创宇 | 依维柯自动挡房车,自行式国产改装房车,小型房车价格,中国十大房车品牌_南京拓锐斯特房车 - 南京拓锐斯特房车 | 彩信群发_群发彩信软件_视频短信营销平台-达信通 | 工业风机_环保空调_冷风机_工厂车间厂房通风降温设备旺成服务平台 | UV固化机_UVLED光固化机_UV干燥机生产厂家-上海冠顶公司专业生产UV固化机设备 | 河南正规膏药生产厂家-膏药贴牌-膏药代加工-修康药业集团官网 | 涡街流量计_LUGB智能管道式高温防爆蒸汽温压补偿计量表-江苏凯铭仪表有限公司 | 车间除尘设备,VOCs废气处理,工业涂装流水线,伸缩式喷漆房,自动喷砂房,沸石转轮浓缩吸附,机器人喷粉线-山东创杰智慧 | 珠海网站建设_响应网站建设_珠海建站公司_珠海网站设计与制作_珠海网讯互联 | 广州工业氧气-工业氩气-工业氮气-二氧化碳-广州市番禺区得力气体经营部 | 防渗土工膜|污水处理防渗膜|垃圾填埋场防渗膜-泰安佳路通工程材料有限公司 | 空心明胶胶囊|植物胶囊|清真胶囊|浙江绿键胶囊有限公司欢迎您! | 郑州墨香品牌设计公司|品牌全案VI设计公司 | 超声波焊接机,振动摩擦焊接机,激光塑料焊接机,超声波焊接模具工装-德召尼克(常州)焊接科技有限公司 | 电力测功机,电涡流测功机,磁粉制动器,南通远辰曳引机测试台 | 附着力促进剂-尼龙处理剂-PP处理剂-金属附着力处理剂-东莞市炅盛塑胶科技有限公司 | 双效节能浓缩器-热回流提取浓缩机组-温州市利宏机械 | 除湿机|工业除湿机|抽湿器|大型地下室车间仓库吊顶防爆除湿机|抽湿烘干房|新风除湿机|调温/降温除湿机|恒温恒湿机|加湿机-杭州川田电器有限公司 | 剪刃_纵剪机刀片_分条机刀片-南京雷德机械有限公司 | 排烟防火阀-消防排烟风机-正压送风口-厂家-价格-哪家好-德州鑫港旺通风设备有限公司 | 储气罐,真空罐,缓冲罐,隔膜气压罐厂家批发价格,空压机储气罐规格型号-上海申容压力容器集团有限公司 | 不锈钢管件(不锈钢弯头,不锈钢三通,不锈钢大小头),不锈钢法兰「厂家」-浙江志通管阀 | 铝箔袋,铝箔袋厂家,东莞铝箔袋,防静电铝箔袋,防静电屏蔽袋,防静电真空袋,真空袋-东莞铭晋让您的产品与众不同 | 户外环保不锈钢垃圾桶_标识标牌制作_园林公园椅厂家_花箱定制-北京汇众环艺 | 电动不锈钢套筒阀-球面偏置气动钟阀-三通换向阀止回阀-永嘉鸿宇阀门有限公司 | 菲希尔X射线测厚仪-菲希尔库伦法测厚仪-无锡骏展仪器有限责任公司 | 酶联免疫分析仪-多管旋涡混合仪|混合器-莱普特科学仪器(北京)有限公司 | 磁力轮,磁力联轴器,磁齿轮,钕铁硼磁铁-北京磁运达厂家 | 外贮压-柜式-悬挂式-七氟丙烷-灭火器-灭火系统-药剂-价格-厂家-IG541-混合气体-贮压-非贮压-超细干粉-自动-灭火装置-气体灭火设备-探火管灭火厂家-东莞汇建消防科技有限公司 | 新疆系统集成_新疆系统集成公司_系统集成项目-新疆利成科技 | 优秀的临床医学知识库,临床知识库,医疗知识库,满足电子病历四级要求,免费试用 | 高低温老化试验机-步入式/低温恒温恒湿试验机-百科 | 水质传感器_水质监测站_雨量监测站_水文监测站-山东水境传感科技有限公司 | 重庆私家花园设计-别墅花园-庭院-景观设计-重庆彩木园林建设有限公司 |