dongwai4434 2018-11-19 11:58 采纳率: 0%
浏览 13740

与“ws:// localhost:8080 /”的WebSocket连接失败:这个报错是怎么回事?

我的客户端脚本和服务器之间没有WebSocket连接,它在我当前的环境中运行得很好。同时,我也遵循这个链接

下面是一个服务器脚本,它初始化WebSocket服务器并让客户端连接到了8080端口。

public function run()
{
    $loop   = Factory::create();
    $pusher = new Pusher;
    $context = new Context($loop);
    $pull = $context->getSocket(ZMQ::SOCKET_PULL);
    $pull->bind('tcp://127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
    $pull->on('message', array($pusher, 'onBlogEntry'));

    // Set up our WebSocket server for clients wanting real-time updates
    $webSock = new Server('0.0.0.0:8080', $loop); // Binding to 0.0.0.0 means remotes can connect
    $webServer = new IoServer(
        new HttpServer(
            new WsServer(
                new WampServer(
                    $pusher
                )
            )
        ),
        $webSock
    );

    $loop->run();

这是客户端脚本:

var conn = new ab.Session('ws://localhost:8080',
    function() {
        /* subscribe to following topics */
        conn.subscribe('new_order', function(topic, data) ..

同样,这在本地设置中运行良好。

还要注意的是,我的应用程序是使用来自docker容器的指定端口承载的。

http://192.168.12.52:8094/xyz/new/....

我还尝试在客户端脚本中指定IP:

var conn = new ab.Session('ws://192.168.12.52:8080',
    function() {
        /* subscribe to following topics */
        conn.subscribe('new_order', function(topic, data) ...

在这种情况下,我会得到以下错误:

WebSocket connection to 'ws://192.168.11.32:8080/' failed: Error during WebSocket handshake: Unexpected response code: 403

这里缺少什么?

</div>
  • 写回答

1条回答 默认 最新

  • dsjzmrz78089 2018-11-19 12:49
    关注

    This is probably an ssl certificate issue. I think new browsers versions have problem with web sockets without ssl. you may have self signed certificate. try https://192.168.12.52:8080 and if you saw an invalid certificate error (something like: Your connection is not secure or Your connection is not private) click advance or add exception then try again with the same browser. also you can use wss:// instead of ws://.

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型