WebSocket握手期间出错:意外的响应代码:500
我在我的网站上使用websocket,但随机发送给我以下错误消息:
WebSocket连接到'ws://client.mydomain.com/socket.io/?EIO = 3&transport = websocket&sid = 4Kbec5T_XStAC949AACS'失败:WebSocket握手期间出错:意外的响应代码: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; }]);
我不是很确定问题是什么,但基本上连接string看起来像这样:
http://client.mydomain.com
谁能告诉我发生了什么事?
你不能通过在Ajax的成功callback里join其余的代码来尝试吗? 喜欢这个:
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; } });
- 如何将后端错误/成功消息从Node.js发送到AngularJS控制器的前端?
- AngularJS路由在html5mode错误
- 如何更改Angular应用程序中的文件path?
- 使用node.js和socket.io进行套接字authentication(使用DaftMonk的generator-angular-fullstack)
- 在根上表示指定的占位符路由
- npm start命令不起作用,并显示mongoose的弃用函数错误
- angular度抛出错误$ parse:ueoe意外的expression式结尾
- 命令“npm install”不起作用
- node.js angular jade客户端和node.js rest api