Socket.io和Node.js无法在Heroku上工作(=错误代码= H13 desc =“连接没有响应关闭”)

时间:2017-04-05 15:28:38

标签: ios node.js heroku socket.io

我正在使用socket.io构建一个iOS应用程序,它在我的localhost上运行正常。 当我将它部署到Heroku时会出现问题。我无法连接到heroku服务器。

服务器日志

  

at =错误代码= H13 desc =“没有响应的连接关闭”方法= GET   path =“/ socket /?transport = websocket”host = my-app-dev.herokuapp.com   request_id = e9c0a348-28d4-4c1c-b10e-175438dcd213 fwd =“”dyno = web.1   connect = 2ms service = 3ms status = 503 bytes = 0 protocol = https

iOS客户端

NSURL *url = [[NSURL alloc] initWithString:@"https://my-app-dev.herokuapp.com"];
self.socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{@"log": @YES, @"forcePolling": @YES,@"path":@"/socket",@"forceWebsockets":@YES}];
[self.socket connect];

服务器(的node.js)

var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server, { path : '/socket'});
io.set('transports', ['websocket']);
io.on('connection', function(socket){
    socket.emit('hello', {'message': 'hello'} ,() => {
      console.log('hello finished');
    });

    socket.on('disconnect', function () {
      console.log(socket.id + ' has disconnected!');
    });
});

0 个答案:

没有答案