web-msg-sender-master跨域名推送

最威武

我有一台阿里云服务器 上面部署了web-msg-sender-master 启动成功 本地调用 返回值ok 然后我再另外一个ip的服务器上写上推送的代码(这个index.html 验证过同ip下可用 ) 现在另外一台ip的项目无法接收到推送消息 请问我怎么写

3372 5 0
5个回答

walkor

贴index.html 内容

  • 暂无评论
最威武
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<link href="main.css" rel="stylesheet" type="text/css" />
<script src='//cdn.bootcss.com/socket.io/1.3.7/socket.io.js'></script>
<script src='//cdn.bootcss.com/jquery/1.11.3/jquery.js'></script>
<script src='/notify.js'></script>
</head>
<body>

<div class="notification sticky hide">
    <p id="content"> </p>
    <a class="close" href="javascript:"> <img src="/icon-close.png" /></a>
</div>
<div class="wrapper">
    <div style="width:850px;">
    <h3>介绍:</h3>
    <b>Web-msg-sender</b> 234是一个web消息推送系统,基于<a rel="nofollow" href="https://github.com/walkor/phpsocket.io">PHPSocket.IO</a>开发。<br><br><br>
    <h3>支持以下特性:</h3>
    <ul>
      <li>多浏览器支持</li>
      <li>支持针对单个用户推送消息</li>
      <li>支持向所有用户推送消息</li>
      <li>长连接推送(websocket或者comet),消息即时到达</li>
      <li>支持在线用户数实时统计推送(见页脚统计)</li>
    </ul>
    <h3>测试:</h3>
    当前用户uid:<b class="uid"></b><br>
    可以通过url2222:<a id="send_to_one" hreasf="" target="_blank"><font style="color:#91BD09">http://<font class="domain"></font>:2123?type=publish&to=<b class="uid"></b>&content=消息内容</font></a>  向当前用户发送消息<br>
    可以通过url:<a href="http://123.57.47.152:2123/?type=publish&to=&content=%E6%B6%88%E6%81%AF%E5%86%85%E5%AE%B9" target="_blank"><font style="color:#91BD09">http://<font class="domain"></font>:2123?type=publish&to=&content=消息内容</font></a> 想所有在线用户推送消息<br>
    <script>
        // 使用时替换成真实的uid,这里方便演示使用时间戳
        var uid = Date.parse(new Date());
        $('#send_to_one').attr('href', 'http://123.57.47.152:2123/?type=publish&content=%E6%B6%88%E6%81%AF%E5%86%85%E5%AE%B9&to='+uid);
        $('.uid').html(uid);
        $('.domain').html(document.domain);
    </script>
</div>

 <script>
$(document).ready(function () {
    // 连接服务端
    var socket = io('http://123.57.47.152:2120');
    // 连接后登录
    socket.on('connect', function(){
        socket.emit('login', uid);
    });
    // 后端推送来消息时
    socket.on('new_msg', function(msg){
         $('#content').html('收到消息:'+msg);
         $('.notification.sticky').notify();    
    });
    // 后端推送来在线数据时
    socket.on('update_online_count', function(online_stat){
        $('#online_box').html(online_stat);
    });
});
</script>

<div id="footer">
<center id="online_box"></center>
<center><p style="font-size:11px;color:#555;"> Powered by <a href="http://www.workerman.net/web-sender" target="_blank"><strong>web-msg-sender!</strong></a></p></center>
</div>
</body>
</html>
  • 暂无评论
walkor

开下防火墙试下

  • 最威武 2016-01-25

    哪个服务器的防火墙 index.html的还是 web-msg-sender-master 的

walkor

发下测试url吧

  • 暂无评论
最威武

经过walkor的解答 原来是notify.js没有加载到

  • 暂无评论
年代过于久远,无法发表回答
🔝