[英]Error during WebSocket handshake: Unexpected response code: 500
i am using a websocket on my site but at random it sends me the following error message:我在我的网站上使用 websocket,但它随机向我发送以下错误消息:
WebSocket connection to 'ws://client.mydomain.com/socket.io/?EIO=3&transport=websocket&sid=4Kbec5T_XStAC949AACS' failed: Error during WebSocket handshake: Unexpected response code: 500 WebSocket 连接到“ws://client.mydomain.com/socket.io/?EIO=3&transport=websocket&sid=4Kbec5T_XStAC949AACS”失败:WebSocket 握手期间出错:意外响应代码:500
Here is how i connect to the websocket in my application (note it is an Angular
application).这是我在我的应用程序中连接到 websocket 的方式(注意它是一个Angular
应用程序)。
app.factory('clientSocket', ['$sessionStorage', 'socketFactory', function ($sessionStorage, socketFactory) {
var connection = '';
$.ajax({
url: 'config.json',
async: false,
dataType: 'json',
success: function (response) {
connection = response.app_url;
}
});
var myIoSocket = io.connect(connection);
var clientSocket = socketFactory({
ioSocket: myIoSocket
});
clientSocket.forward('someEvent');
clientSocket.on('connect', function () {
if ($sessionStorage.activeUser != null) {
clientSocket.emit('userData', $sessionStorage.activeUser.user);
}
});
return clientSocket;
}]);
Im not quite sure what the problem is but basicly the connection string looks like this:我不太确定问题出在哪里,但基本上连接字符串如下所示:
http://client.mydomain.com
Can anyone tell me whats going on?谁能告诉我发生了什么事?
Can't you try it by adding the rest of the code inside the success callback of ajax?你不能通过在ajax的成功回调中添加其余代码来尝试吗? Like this:像这样:
app.factory('clientSocket', ['$sessionStorage', 'socketFactory', function ($sessionStorage, socketFactory) {
var connection = '';
$.ajax({
url: 'config.json',
async: false,
dataType: 'json',
success: function (response) {
connection = response.app_url;
var myIoSocket = io.connect(connection);
var clientSocket = socketFactory({
ioSocket: myIoSocket
});
clientSocket.forward('someEvent');
clientSocket.on('connect', function () {
if ($sessionStorage.activeUser != null) {
clientSocket.emit('userData', $sessionStorage.activeUser.user);
}
});
return clientSocket;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.