• 用openfire+strophe搭建WEB IM平台


    用openfire+strophe搭建WEB IM平台 - nomousewch的专栏 - 博客频道 - CSDN.NET

    • 准备
    1. openfire服务器(http://www.igniterealtime.org)——IM Server
    2. ngnix服务器(http://nginx.org)——代理和HTTP Server
    3. strophe库(http://strophe.im/)——JS客户端
    • 安装和配置openfire

             openfire的安装见本人博客,安装时配置domain为172.17.125.161(注意除非PC配置了域名,不然最好domain配置为IP,方便客户端访问),后登录管理控制台,服务器》服务器设置》HTTP绑定,默认启用7070端口作为HTTP绑定端口。

    • 安装和配置nginx

             我安装的是windows版,直接解压到本地目录,打开conf目录下nginx.conf,修改server节点为如下:

    1. server {  
    2.         listen       80;  
    3.         server_name  172.17.125.161;  
    4.   
    5.         #charset koi8-r;  
    6.   
    7.         #access_log  logs/host.access.log  main;  
    8.   
    9.         location / {  
    10.             root   html;  
    11.             index  index.html index.htm;  
    12.         }  
    13.   
    14.     location /http-bind {  
    15.             proxy_pass http://172.17.125.161:7070/http-bind/;  
    16.             proxy_redirect off;  
    17.             proxy_read_timeout 120;  
    18.             proxy_connect_timeout 120;  
    19.    
    20.        }  
    21.   
    22.   
    23.         #error_page  404              /404.html;  
    24.   
    25.         # redirect server error pages to the static page /50x.html  
    26.         #  
    27.         error_page   500 502 503 504  /50x.html;  
    28.         location = /50x.html {  
    29.             root   html;  
    30.         }  
    31.   
    32.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
    33.         #  
    34.         #location ~ .php$Snbsp;{  
    35.         #    proxy_pass   http://127.0.0.1;  
    36.         #}  
    37.   
    38.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
    39.         #  
    40.         #location ~ .php$Snbsp;{  
    41.         #    root           html;  
    42.         #    fastcgi_pass   127.0.0.1:9000;  
    43.         #    fastcgi_index  index.php;  
    44.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  
    45.         #    include        fastcgi_params;  
    46.         #}  
    47.   
    48.         # deny access to .htaccess files, if Apache's document root  
    49.         # concurs with nginx's one  
    50.         #  
    51.         #location ~ /.ht {  
    52.         #    deny  all;  
    53.         #}  
    54.     }  
    server {
            listen       80;
            server_name  172.17.125.161;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
    
    	location /http-bind {
                proxy_pass http://172.17.125.161:7070/http-bind/;
                proxy_redirect off;
                proxy_read_timeout 120;
                proxy_connect_timeout 120;
    
           }
    
            #error_page  404              /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ .php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ .php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /.ht {
            #    deny  all;
            #}
        }

            然后双击nginx.exe,在任务管理器下看到两个nginx.exe进程说明启动成功。

    • 安装strophe

            下载strophejs-1.0.2.zip包,直接解压至nginx目录下的html文件夹内。

    • 测试连接

             进入strophejs-1.0.2解压目录,打开examples/basic.js,修改

    1. var BOSH_SERVICE = 'http://im/http-bind/'  
    var BOSH_SERVICE = 'http://im/http-bind/'

             为:

    1. var BOSH_SERVICE = 'http://172.17.125.161/http-bind/'  
    var BOSH_SERVICE = 'http://172.17.125.161/http-bind/'



            打开浏览器,访问 http://172.17.125.161/strophejs-1.0.2/examples/basic.html,输入完整的JID(例如:nomouse@172.17.125.161)和密码,点击connect,出现下列输入说明登录成功:

    1. SENT: <body rid='4218693533' xmlns='http://jabber.org/protocol/httpbind' to='172.17.125.161' xml:lang='en' wait='10' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>  
    2. RECV: <body xmlns='http://jabber.org/protocol/httpbind' xmlns:stream='http://etherx.jabber.org/streams' authid='74ec6e82' sid='74ec6e82' secure='true' requests='2' inactivity='30' polling='0' wait='10' hold='1' ack='4218693533' maxpause='300' ver='1.6'><stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns='http://jabber.org/features/compress'><method>zlib</method></compression><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></stream:features></body>  
    3. SENT: <body rid='4218693534' xmlns='http://jabber.org/protocol/httpbind' sid='74ec6e82'><auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/></body>  
    4. SENT: <body rid='4218693534' xmlns='http://jabber.org/protocol/httpbind' sid='74ec6e82'><auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/></body>  
    5. SENT: <body rid='4218693534' xmlns='http://jabber.org/protocol/httpbind' sid='74ec6e82'><auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/></body>  
    SENT: <body rid='4218693533' xmlns='http://jabber.org/protocol/httpbind' to='172.17.125.161' xml:lang='en' wait='10' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>
    RECV: <body xmlns='http://jabber.org/protocol/httpbind' xmlns:stream='http://etherx.jabber.org/streams' authid='74ec6e82' sid='74ec6e82' secure='true' requests='2' inactivity='30' polling='0' wait='10' hold='1' ack='4218693533' maxpause='300' ver='1.6'><stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns='http://jabber.org/features/compress'><method>zlib</method></compression><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></stream:features></body>
    SENT: <body rid='4218693534' xmlns='http://jabber.org/protocol/httpbind' sid='74ec6e82'><auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/></body>
    SENT: <body rid='4218693534' xmlns='http://jabber.org/protocol/httpbind' sid='74ec6e82'><auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/></body>
    SENT: <body rid='4218693534' xmlns='http://jabber.org/protocol/httpbind' sid='74ec6e82'><auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/></body>
  • 相关阅读:
    Spyder | 关于报错No module named 'PyQt5.QtWebKitWidgets'
    Java基础(11) | 接口
    Java基础(10) | 抽象
    Java基础(9) | 继承
    Java基础(7) | String
    Java基础(6) | ArrayList
    CodeBlocks17.12配置GNU GCC + 汉化
    图片懒加载
    Mac安装Mysql 超详细(转载)
    剑指 Offer 03. 数组中重复的数字
  • 原文地址:https://www.cnblogs.com/seven1979/p/4221959.html
Copyright © 2020-2023  润新知