gpt4 book ai didi

javascript - WebSocket 握手错误 : Unexpected response code: 500

转载 作者:搜寻专家 更新时间:2023-10-31 22:54:35 24 4
gpt4 key购买 nike

我在我的网站上使用 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 的方式(注意它是一个 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;
}]);

我不太确定问题出在哪里,但基本上连接字符串如下所示:

http://client.mydomain.com

谁能告诉我这是怎么回事?

最佳答案

您不能通过将其余代码添加到 ajax 的成功回调中来尝试一下吗?像这样:

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;
}
});

关于javascript - WebSocket 握手错误 : Unexpected response code: 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33477011/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com