【问题标题】:Receiving "InvalidStateError: DOM Exception 11" during websocket.send在 websocket.send 期间收到“InvalidStateError: DOM Exception 11”
【发布时间】:2013-02-26 11:50:39
【问题描述】:

我收到此错误:

DOM Invalidate exception 11 

从下面的代码,但我找不到原因。

/*This is little bit pseudo stylish coded so might have some 
syntax errors */

    var socket;
    var client = {
        connect: function(){
            socket = new WebSocket(mylocation);
            socket.onopen = this.open;
            socket.send = this.send;
        },
        open: function(){
            this.send("Sent from socket open function");   //works
            socket.send("Sent from socket open function");  //works
        },
        _send: function(){
            socket.send("Sent from send function");     //error
            this.send("Sent from send function");       //error
        }
    }

    client.connect();
    client._send();

    ----- ERROR DESCRIPTION --------
    //DOMException {message: "InvalidStateError: DOM Exception 11", 
    //name: "InvalidStateError", code: 11

我目前正在为服务器使用 Java Jetty Websocket。这个错误是什么意思?

【问题讨论】:

    标签: java javascript websocket jetty


    【解决方案1】:

    根据我的经验,这个错误通常意味着服务器很忙/或者现有的 websocket 连接被阻塞,并且不允许新的 websocket 连接。我不熟悉 Jetty,但是当第二个浏览器在现有连接关闭之前尝试连接时,我在由 uWSGI+gevent 组成的服务器上遇到同样的错误——它在任何给定时间最多允许一个 websocket 连接,它恰好得到这个错误。

    【讨论】:

      【解决方案2】:

      这里有无限递归函数:

      send: function(){
          socket.send("Sent from send function");     //error
          this.send("Sent from send function");       //error <--
      }
      

      【讨论】:

      • 这不是问题。我把 send 改成了 _send 但还是不行=(
      • 我找到的唯一当前解决方案是传递 .onopen evenlistener 方法的这个(上下文)。
      猜你喜欢
      • 2016-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-23
      • 2018-01-04
      • 2022-10-14
      • 1970-01-01
      • 2012-06-26
      相关资源
      最近更新 更多