dongzhu0327 2017-11-23 07:33
浏览 199

无法使用websocket在浏览器上运行客户端

I want to create a real time Web chat app.

And trying to do it with ratchet. As a beginner I am not able to understand where I m Goin wrong. I have copied the whole Content from socketo.me and it worked in terminal using "telnet localhost 8080" but when I want to achieve the same thing using my browser it doesn't.

I put localhost:8080 in url and shows blank, where I want to view my index.php.

Plz help me. Where the localhost:8080 is pointing and where should I place my index. Php

my directory looks like this

  • 写回答

1条回答 默认 最新

  • dongwei1263 2017-11-23 07:49
    关注

    You have to create html file containing javascript for you to able to communicate with your websocket server, please refer to ratchet docs (http://socketo.me/docs/push#client).

    <script src="https://gist.githubusercontent.com/cboden/fcae978cfc016d506639c5241f94e772/raw/e974ce895df527c83b8e010124a034cfcf6c9f4b/autobahn.js"></script>
    <script>
        var conn = new ab.Session('ws://localhost:8080',
            function() {
                conn.subscribe('kittensCategory', function(topic, data) {
                    // This is where you would add the new article to the DOM (beyond the scope of this tutorial)
                    console.log('New article published to category "' + topic + '" : ' + data.title);
                });
            },
            function() {
                console.warn('WebSocket connection closed');
            },
            {'skipSubprotocolCheck': true}
        );
    </script>
    

    use google chrome console to see the logs (F12)

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料