2

I have pushed a Phoenix app to Heroku and it is running fine, apart from connecting to a channel from iOS.

Channels over the browser work as expected.

In iOS I am using PhoenixWebSocket, and in dev env, connecting to the local Phoenix app works as expected.

The problem I am getting is when I point the web socket url to the Heroku app I get the following error:

Error Domain=WebSocket Code=301 "Invalid HTTP upgrade" UserInfo={NSLocalizedDescription=Invalid HTTP upgrade}

Looking around for the error message earlier today, I found a post from Chris McCord, I think it was, saying that this error message is a result of the server refusing to upgrade the request.

However, I've looked around Heroku and found that; Websockets functionality is supported for all applications.

So I'm confused as to whether my problem is on the iOS side, or the Heroku side.

I have pushed Chris's example chat application to Heroku, and tried to connect with the demo app that comes with PhoenixWebSocket, but get the same error.

Has anyone else managed to get web socket requests working between iOS and Heroku hosting a Phoenix app?

Would anyone know if there is something differently I need to do with the request in iOS before trying to join the channel? Or, maybe there is something with the Heroku setup relating to web sockets that I've missed?

The url for the request in iOS:

let url = NSURL(string: "ws://app-name-32793.heroku.com/socket/websocket")!

Many thanks to anyone that can help, and please let me know if there's anything else I can supply to help.

Paul

paul h
  • 152
  • 2
  • 10
  • Paul, did you have any luck solving this? I'm running into the same issue - also using an iOS client with a Phoenix backend hosted on Heroku. – fastredshoes Jun 28 '16 at 16:54
  • Unfortunately no. I'm currently setting up my own Centos 7 server as a result. If I find anything to fix the heroku issue, I'll post back. – paul h Jun 29 '16 at 09:48
  • @fastredshoes I haven't gone back and tried to fix the Heroku issue, because I have fixed the same problem on my own server. I did it with the help I found at this post: [link](http://stackoverflow.com/questions/38229629/how-to-set-up-websockets-with-phoenix-behind-nginx/38230388?noredirect=1#comment63907382_38230388). HTH You. – paul h Jul 11 '16 at 15:17
  • it did! Thank you. – fastredshoes Jul 12 '16 at 15:04

1 Answers1

0

I know this is old but one possible issue is you may need to connect via https/wss. So either

let url = NSURL(string: "wss://app-name-32793.heroku.com/socket/websocket")!

or:

let socket = Socket(domainAndPort: "app-name-32793.heroku.com", path: "socket", transport: "websocket", prot: "https", params: [])

Jason Axelson
  • 4,485
  • 4
  • 48
  • 56