yii-node-socket 对我不起作用 [英] yii-node-socket is not working for me

查看:24
本文介绍了yii-node-socket 对我不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我一直在尝试将 nodejs 与我现有的项目集成,以确保实时更新提要.因此,我使用了以下 yii 插件并按照说明进行操作:

<块引用>

https://github.com/oncesk/yii-node-socket

主机和端口分别是:bigcat,3001,我已经在console.php和main.php中配置了它们.我启动了节点服务器,日志显示它正在监听:

听bigcat:3001设置来源:bigcat:*

在我的客户端,我有以下代码(我将其创建为外部 javascript):

//创建对象并连接到 Web 套接字服务器var socket = new YiiNodeSocket();socket.on('event.example', function () {console.log('*****Trigger test.event, 是一个全局事件,适用于所有客户端 *****');});socket.onConnect(函数(){socket.room('example').join(function (isConnected, numberOfRoomClients) {如果(已连接){//只为这个房间捕获 test.eventconsole.log('***加入房间示例:会员数[' + numberOfRoomClients + ']*****');this.on('example.room.event', function (data) {console.log('****工作****');});}});});

我的控制台记录客户端连接成功.一个在homeController的测试方法,我有如下代码:

 $event = Yii::app()->nodeSocket->getFrameFactory()->createEventFrame();$event->setRoom('example');$event->setEventName('example.room.event');$event['type_string'] = 'hello world';$event['type_array'] = array(1, 2, 3);$event['type_object'] = array('one' => 1, 'two' => 2);$event['type_bool'] = true;$event['type_integer'] = 11;$event->send();

当我在另一个浏览器中调用 homeController 测试方法时,我的客户端应该能够监听事件并且控制台应该打印IT's WORKING".然而,这并没有发生.我的日志显示以下错误:

warn: 握手错误 INVALID SERVER: server host 127.0.0.1 not allowed for/server调试:websocket 写 7::/server:undefined

服务器端代码似乎根本不起作用.我能不能得到一些关于如何完成它的建议.我觉得我很近又很远.

server.config.js 设置为:

module.exports = {主持人:'大猫',端口 : parseInt('3001'),原点:'大猫:*',allowedServers : ["127.0.1.1"],dbOptions : {"driver":"dummy","config":[]},checkClientOrigin : 1,sessionVarName : 'PHPSESSID'};

解决方案

我觉得你需要在 yii 配置文件中添加 127.0.0.1 -> 节点套接字配置部分 -> 参数是 allowedServerAddresses

像这样^

'nodeSocket' =>大批('类' =>'application.extensions.yii-node-socket.lib.php.NodeSocket','主机' =>'localhost',//默认为127.0.0.1,可以是ip或域名,不带http'端口' =>3001//默认是 3001,应该是整数,<b>'allowedServerAddresses' =>数组('127.0.0.1'))

你能显示 node-socket/lib/js/server/server.config.js 配置文件吗?

Recently I have been trying to integrate nodejs with my existing project to make sure of live updating of feeds. Thus, I used the following yii plugin and followed the instruction:

https://github.com/oncesk/yii-node-socket

The host and port are: bigcat,3001 respectively and I have configured them in the console.php and main.php as mentioned. I started the node server and the log indicated that it was listening to:

Listening bigcat:3001
Set origin: bigcat:*

At my client side I have the following codes (i created it as an external javascript):

// create object and connect to web socket server
var socket = new YiiNodeSocket(); 

socket.on('event.example', function () {
    console.log('*****Trigger test.event, is a global event, for all clients*****');
});

socket.onConnect(function () {
    socket.room('example').join(function (isConnected, numberOfRoomClients) {
        if (isConnected) {
            // catch test.event only for this rooom
            console.log('***Joined into room example: members count [' + numberOfRoomClients + ']*****');
            this.on('example.room.event', function (data) {
                 console.log('****WORKING****');
            });
        }
    });
});

My console records that the client is successfully connected.An at homeController test method, I have the following code:

 $event = Yii::app()->nodeSocket->getFrameFactory()->createEventFrame();
 $event->setRoom('example');
 $event->setEventName('example.room.event');
 $event['type_string'] = 'hello world';
 $event['type_array'] = array(1, 2, 3);
 $event['type_object'] = array('one' => 1, 'two' => 2);
 $event['type_bool'] = true;
 $event['type_integer'] = 11;
 $event->send();

When I invoke the homeController test method in another browser, my client should be able to listen to the event and the console should print "IT's WORKING". However, that is not happening. My log is showing the following error:

warn: handshake error INVALID SERVER: server host 127.0.0.1 not allowed for /server
debug: websocket writing 7::/server:undefined

The server side codes seems to not work at all. Could I get some advice on how to get it done. I feel I am close and yet far.

The server.config.js setting is:

module.exports = {
    host : 'bigcat',
    port : parseInt('3001'),
    origin : 'bigcat:*',
    allowedServers : ["127.0.1.1"],
    dbOptions : {"driver":"dummy","config":[]},
    checkClientOrigin : 1,
    sessionVarName : 'PHPSESSID'
};

解决方案

I think you need to add 127.0.0.1 in yii config file -> node socket configuration section -> parameter is allowedServerAddresses

Like this^

'nodeSocket' => array(
    'class' => 'application.extensions.yii-node-socket.lib.php.NodeSocket',
    'host' => 'localhost',  // default is 127.0.0.1, can be ip or domain name, without http
    'port' => 3001      // default is 3001, should be integer,
    <b>'allowedServerAddresses' => array('127.0.0.1')</b>
)

And can you show node-socket/lib/js/server/server.config.js config file?

这篇关于yii-node-socket 对我不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆