Receiving “InvalidStateError: DOM Exception 11” during websocket.send

╄→尐↘猪︶ㄣ 提交于 2020-01-15 03:20:26

问题


I am getting this error:

DOM Invalidate exception 11 

From following code but I cannot find the cause.

/*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

I am currently using Java Jetty Websocket for the server. What does this error mean?


回答1:


Here you have infinite recursive function:

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



回答2:


From my experience, this error typically means the server is busy / or that existing websocket connections are blocking, and are not allowing new websocket connections. I'm not familiar with Jetty, but I get the same error with a server consisting of uWSGI+gevent -- which allows at most one websocket connection at any given time -- when a second browser tries to connect before the existing connection is closed, it gets precisely this error.



来源:https://stackoverflow.com/questions/15088388/receiving-invalidstateerror-dom-exception-11-during-websocket-send

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!