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

与“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://.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?