node.js - 如何在 Heroku 上获取我的 Node 应用程序的准确 Web 套接字 url

标签 node.js swift heroku websocket socket.io

我按照教程在heroku 上使用node.js 托管聊天应用程序后端。来源可用here .

它目前托管在 Heroku 上并且目前运行良好。网址是here .

我的问题是如何在我的移动应用程序上连接此网络套接字?套接字的确切 URL 是什么?

使用https://shielded-everglades-33427.herokuapp.com/ws://shielded-everglades-33427.herokuapp.com/不起作用.

我正在使用带有Socket.IO-Client-Swift库的iOS应用程序来测试套接字,相关部分在这里:

func connectToSocketUI(){
        let socketURL = URL(string: "ws://shielded-everglades-33427.herokuapp.com:443")!
        let manager = SocketManager(socketURL: socketURL)
        let socketIO = manager.defaultSocket

        socketIO.on(clientEvent: .connect) { (data, ack) in
            print("Connected to Socket.io")
        }

        socketIO.on(clientEvent: .disconnect) { (data, ack) in
            print("Disconnected to Socket.io")
        }

        socketIO.on("newMessage") { (data, ack) in
            print(data)
        }

        socketIO.connect(timeoutAfter: 3) {
            print("Error")
        }
    }

最佳答案

由于您的 Heroku 应用程序通过 https 提供服务,因此您应该使用 wss://

试试这个:

wss://shielded-everglades-33427.herokuapp.com/

关于node.js - 如何在 Heroku 上获取我的 Node 应用程序的准确 Web 套接字 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51874724/

相关文章:

node.js - headless Chrome 脚本使用同一 session 并跳过双因素身份验证

javascript - Digitalocean 使用 nginx 部署 Node https 应用程序

objective-c - 从 CMSampleBuffer 制作 UIImage 会发生什么?

python - 你如何在 Heroku 中安装 Rtree?

Heroku中的Python cx_Oracle

java - Heroku War 部署 SSL 错误

javascript - 嵌套的 Jade block 没有被渲染

javascript - 下一个JS : async getInitialProps() with AWS S3?

ios - 无法使用类型为“(String, withIntermediateDirectories : B) 的参数列表调用 'createDirectoryAtPath'

swift - 使用枚举迭代可选值