The WebSocket(url, protocols) constructor takes one or two arguments. The first argument, url, specifies the URL to which to connect. The second, protocols, if present, is either a string or an array of strings. If it is a string, it is equivalent to an array consisting of just that string; if it is omitted, it is equivalent to the empty array. Each string in the array is a subprotocol name. The connection will only be established if the server reports that it has selected one of these subprotocols. The subprotocol names must all be strings that match the requirements for elements that comprise the value of Sec-WebSocket-Protocol fields as defined by the WebSocket protocol specification.
您的服务器用空的Sec-WebSocket-Protocol头响应websocket连接请求,因为它不支持Chat-1子目录。
因为您同时在编写服务器端和客户端(并且除非您编写了要共享的API),所以设置特定的子目录名称不应该是非常重要的。
可以通过从javascript连接中删除子目录名称来解决此问题:var socket = new WebSocket(serviceUrl);
或者修改服务器以支持请求的协