如何启动我的网站要使用的socket.io-redis服务器. [英] How to start a socket.io-redis server to be used by my website.

查看:140
本文介绍了如何启动我的网站要使用的socket.io-redis服务器.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我在bluehost.com上使用wordpress.我的域名是"mysimplesurvey.com".我的目标是建立一些网页,这些网页具有多个用户登录并与同一个MySql数据库进行通信.当一个用户更改数据库中的某些内容时,我希望通过触发器使某些信息自动推送给其他已登录的用户.
我刚刚观看了Guillermo Rauch最近创建的一个在线视频,名为与Socket.IO和WordPress进行实时通信".这说服了我使用node.js,socket.io和socket.io-redis来实现浏览器和服务器js脚本之间的双向通信的目标.所以我安装了node.js. socket.io和socket.io redis.我购买了专用的ip,并获得了技术支持,以为socket.io打开端口9100,并为redis打开端口6379.
到目前为止,我已经能够使用socket.io在ssh上运行的两个js脚本之间进行通信.但是我还没有使用redis完成php(在wordpress页面上)和node.js socket.io服务器之间的双向通信.根据我在网上看到的内容,我需要启动一个socket.io-redis服务器,并将其作为主要步骤之一来运行. Guillermo的演示非常简单.但是我还无法弄清楚如何使Redis服务器正常运行.有谁知道如何通过在bluehost站点上使用ssh来启动socket.io-redis服务器?
以下是简单的服务器端js测试代码,如果redis服务器已启动并正在运行,则应正确运行.

//节点服务器文件emsave.js
var io = require(''socket.io'')(9100);
io.adapter(require(''socket.io-redis'')
({host:``http://www.mysimplesurvey.com''})));
io.on(''connection'',function(){
console.log(``这应该可以工作'');
});

现在尝试在服务器的ssh上运行此代码将返回以下错误:

mysimpp7@mysimplesurvey.com [〜/public_html/EmitterPHP]#节点emsave.js
events.js:85
投掷者//未处理的错误"事件
^
错误:Redis与http://www.mysimplesurvey.com:6379的连接失败-getaddrinfo ENOTFOUND http://www.mysimplesurvey.com
在RedisClient.flush_and_error(/home2/mysimpp7/public_html/EmitterPHP/node_modules/socket.io-redis/node_modules/redis/index.js:142:13)
在RedisClient.on_error(/home2/mysimpp7/public_html/EmitterPHP/node_modules/socket.io-redis/node_modules/redis/index.js:180:10)
< anonymous>. (/home2/mysimpp7/public_html/EmitterPHP/node_modules/socket.io-redis/node_modules/redis/index.js:95:14)
在Socket.emit(events.js:107:17)
在net.js:915:16
在process._tickCallback(node.js:343:11)
mysimpp7@mysimplesurvey.com [〜/public_html/EmitterPHP]#

在网络上,似乎没有很多人做过这样的事情,而且我可能是bluehost上第一个尝试这样做的人.我在bluehost.com论坛,wordpress.org论坛和wordpress.com论坛上也提出了类似的问题.我引起了一些兴趣,但到目前为止还没有解决的办法.
谢谢,
Phil Marks Sr.

Hi, I am using wordpress at bluehost.com . My domain is "mysimplesurvey.com". My aim is to set up some webpages which have multiple users logged on and communicating with the same MySql database. When one user changes certain things in the database, I would like triggers to cause certain information to be automatically pushed to other logged-on users.
I just watched an online video, just recently created by Guillermo Rauch called "Realtime Communication with Socket.IO and WordPress". This has convinced me to use node.js, socket.io and socket.io-redis to accomplish my aims for bi-directional communications between browsers and server js script. So i installed node.js. socket.io, and socket.io redis. I bought a dedicated ip, and got tech support to open a port 9100 for socket.io, and also port 6379 for redis.
So far I have been able to communicate between two js scripts running on ssh using socket.io. However i have yet to accomplish bidirectional communication between php (on a wordpress page) and a node.js socket.io server, using redis. From what i have seen on-line, I need to get a socket.io-redis sever up and running as one of the main steps. The demo by Guillermo is straight forward. But i have not been able to figure out how to get that redis server going. Does anyone know how to get a socket.io-redis server started through using ssh on a bluehost site?
The following is the simple server-side js test code which should run without errors if the redis sever were up and running.

// node server file emsave.js
var io= require(''socket.io'')(9100);
io.adapter(require(''socket.io-redis'')
({ host: ''http://www.mysimplesurvey.com''}));
io.on(''connection'',function(){
console.log(''this should work'');
});

Right now trying to run this code on my server''s ssh returns the following error:

mysimpp7@mysimplesurvey.com [~/public_html/EmitterPHP]# node emsave.js
events.js:85
throw er; // Unhandled ''error'' event
^
Error: Redis connection to http://www.mysimplesurvey.com:6379 failed - getaddrinfo ENOTFOUND http://www.mysimplesurvey.com
at RedisClient.flush_and_error (/home2/mysimpp7/public_html/EmitterPHP/node_modules/socket.io-redis/node_modules/redis/index.js:142:13)
at RedisClient.on_error (/home2/mysimpp7/public_html/EmitterPHP/node_modules/socket.io-redis/node_modules/redis/index.js:180:10)
at Socket.<anonymous> (/home2/mysimpp7/public_html/EmitterPHP/node_modules/socket.io-redis/node_modules/redis/index.js:95:14)
at Socket.emit (events.js:107:17)
at net.js:915:16
at process._tickCallback (node.js:343:11)
mysimpp7@mysimplesurvey.com [~/public_html/EmitterPHP]#

On the web, there doesn''t seem to be a whole lot of people who have done something like this, and i may be the first one on bluehost to try it. I have similar questions posed at bluehost.com forums, wordpress.org forums, and wordpress.com forums. I have generated some interest, but no solutions so far.
Thanks,
Phil Marks Sr.

推荐答案

以下是解决方案的开始:我学习了如何启动后台Java脚本,以及如何从Java脚本建立套接字连接. php模板文件.然后,脚本和模板可以通过套接字来回发送消息.首先,我必须从bluehost购买专用的IP地址.然后,我必须安装node.js,socket.io,socket.io-server,socket.io-redis和Redis.然后,我让bluehost打开了端口9100和6379.然后,我必须确保我的php安装版本为5.3或更高.然后我配置了ssh.

这是后台脚本的代码.它所在的文件是"em.js".您可以将代码放在您选择的.js文件中.
Here are the beginnings of a solution: I learned how to start a background java script, and how to make a socket connection to it from a php template file. Then the script and the template can send messages back and forth over the socket. First I had to purchase a dedicated IP address from bluehost. Then I had to install node.js, socket.io, socket.io-server, socket.io-redis, and redis. Then I had bluehost open up ports 9100 and 6379. Then i had to make sure my php install is version 5.3 or greater. Then i configured ssh.

Here is the code for the background script. the file it is in is "em.js". You can put the code in the .js file of your choosing.
// node server file emsave.js
var io= require('socket.io')(9100);
io.adapter(require('socket.io-redis')
({ host: 'your dedicated IP address here'})); // supply your dedicted ip address here
console.log('Server is listening on 9100');
io.on('connection',function(socket){
console.log('connection just made');
socket.on('disconnect', function () {
console.log('connection just closed');
});
socket.on('message', function (msg) {
console.log(msg);
socket.send(msg);
});
});

to run the above, log in to ssh and type in the following command: node em.js


Here is the php template:

/*
Template Name: EmitterPHP
*/
/*
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
?>
namespace myapp;
use SocketIO\emitter;
class OrganizationUpdates
{
public


主机; public
host; public


port = 6379; 私人
port = 6379; private


这篇关于如何启动我的网站要使用的socket.io-redis服务器.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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