脚本宝典收集整理的这篇文章主要介绍了使用带有voryx Thruway WAMP消息系统的php发送消息,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
这实际上非常简单,可以通过几种不同的方式完成.我们设计了Thruway客户端来模仿AutobahnJS客户端,因此大多数简单示例都将直接翻译.
在您的PHP网站中,您需要执行以下操作:
@H_126_20@$connection = new \Thruway\Connection( [ "realm" => 'com.example.astro',"url" => 'ws://demo.thruway.ws:9090',//You can use this demo server or replace IT with your router's IP ] ); $connection->on('oPEn',function (\Thruway\ClientSession $session) use ($connection) { //publish an event $session->publish('com.example.hello',['Hello,world From PHP!!!'],[],["ackNowlEdge" => true])->then( function () use ($connection) { $connection->close(); //You must close the connection or this will hang echo "Publish AckNowledged!\n"; },function ($error) { // publish Failed echo "Publish Error {$error}\n"; } ); }); $connection->open();
而javascript客户端(使用AutobahnJS)将如下所示:
VAR connection = new autobahn.Connection({ url: 'ws://demo.thruway.ws:9090',//You can use this demo server or replace it with your router's IP realm: 'com.example.astro' }); connection.onopen = function (session) { //subscribe to a topic function onevent(args) { console.LOG("Someone published this to 'com.example.hello': ",args); } session.subscribe('com.example.hello',onevent).then( function (subscription) { console.log("subscription info",subscription); },function (error) { console.log("subscription error",error); } ); }; connection.open();
以上是脚本宝典为你收集整理的使用带有voryx Thruway WAMP消息系统的php发送消息全部内容,希望文章能够帮你解决使用带有voryx Thruway WAMP消息系统的php发送消息所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。