Strophe的示例程序运行
在看《XMPP高级编程》时,第一个程序就跑不起来,因为书中提供的BOSH连接管理器不可用。
安装准备
下载Openfire并安装:http://www.igniterealtime.org/downloads/index.jsp
下载Strophe.js:http://strophe.im/strophejs/
下载Nginx或者Apache并安装配置:只需一个,作为80端口服务的代理转发服务器(本文没有测试Apache)
安装配置
具体为:登录Openfire管理控制台->服务器->服务器设置->HTTP绑定(英文界面:Server->Server Settings->Http Binding)做如下设置:
Nginx的配置
打开nginx的配置文件nginx.conf,增加如下行:
01 | server { |
02 | listen 80; |
03 | server_name localhost; |
04 | ... |
05 |
06 | location / { |
07 | root html; |
08 | index index.html index.htm; |
09 | } |
10 |
11 | #-----添加的Begin----- |
12 | location /http-bind { |
13 | proxy_pass http://127.0.0.1:7070; |
14 | proxy_buffering off; |
15 | proxy_redirect off; |
16 | proxy_read_timeout 120; |
17 | proxy_connect_timeout 120; |
18 | tcp_nodelay on; |
19 | } |
20 | #-----添加的End----- |
21 |
22 | #error_page 404 /404.html; |
启动nginx,打开命令行,进行nginx目录,输入start nginx
将下载的strophejs文件解压至Ngnix的html文件夹中,在strophejs/examples文件夹中有一些示例文件,修改"*.js"文件中的BOSH_SERVICE为'/http-bind/'即可。(这里有个问题,示例程序中使用的jQuery有点过时,加载较慢,手动下载jQuery进行替换,能加快载入速度)这里以echobot.js为例:
编辑echobot.js,修改第一行为:
1 | var BOSH_SERVICE = '/http-bind/' ; |
使用Openfire中的用户进行登录,如图。
在这里可以安装Spark进行测试。
在 httpd.conf 中加入下面几行:
LoadModule proxy_module modules/mod_proxy.so ProxyRequests Off |
注:需要apache有编译proxy模块
参考文档:
A short tutorial on Echobot by Alfred Westerveld
Anders Conbere’s guide to BOSH, ejabberd, Firefox, and Strophe
WEBIM的简单实现