librelist archives

« back to archive

Need alternative way to set host and port

Need alternative way to set host and port

From:
Bruce Eckel
Date:
2015-03-04 @ 20:41
I'm working on getting the example on this page:
https://github.com/miguelgrinberg/Flask-SocketIO

To work under Heroku. Here's my project so far:
https://github.com/BruceEckel/hello-flask-websockets

To get this to work, I can't call
    app.run(host='0.0.0.0', port=port)
directly, because the SocketIO object has to do it:
    socketio.run(app)

I've tried setting host and port like this:
    app.config['host'] = '0.0.0.0'
    app.config['port'] = int(os.environ.get("PORT", 5000))
    socketio.run(app)

But to no avail.

Thanks in advance.

-- Bruce Eckel
www.MindviewInc.com <http://www.mindviewinc.com/>
Blog: www.BruceEckel.github.io
www.WinterTechForum.com
www.AtomicScala.com
www.Reinventing-Business.com
www.ScalaSummit.com

Re: [flask] Need alternative way to set host and port

From:
Keyan Pishdadian
Date:
2015-03-04 @ 20:51
Hi Bruce,

I just played around with that extension last week so I have some advice. 
The good news is you can add those arguments like you would when running 
the normal server:

socketio.run(app, host=‘0.0.0.0’, port=port)

The bad news is that Heroku is very weird about Socket.io. What ended up 
happening for me was that I could get two client browsers to interact but 
only if they accessed the server within a certain amount of time of each 
other. In general using Socket.io on Heroku is going to be no fun. I ended
up switching to an AWS Ubuntu EC2 instance and it is running great. Get in
touch if you want to talk about it some more.

Good luck,
Keyan

On Mar 4, 2015, at 3:41 PM, Bruce Eckel <bruceteckel@gmail.com> wrote:

> I'm working on getting the example on this page:
> https://github.com/miguelgrinberg/Flask-SocketIO
> 
> To work under Heroku. Here's my project so far:
> https://github.com/BruceEckel/hello-flask-websockets
> 
> To get this to work, I can't call
>     app.run(host='0.0.0.0', port=port)
> directly, because the SocketIO object has to do it:
>     socketio.run(app)
> 
> I've tried setting host and port like this:
>     app.config['host'] = '0.0.0.0'
>     app.config['port'] = int(os.environ.get("PORT", 5000))
>     socketio.run(app)
> 
> But to no avail.
> 
> Thanks in advance.
> 
> -- Bruce Eckel
> www.MindviewInc.com
> Blog: www.BruceEckel.github.io
> www.WinterTechForum.com
> www.AtomicScala.com
> www.Reinventing-Business.com
> www.ScalaSummit.com
> 

Re: [flask] Need alternative way to set host and port

From:
Bruce Eckel
Date:
2015-03-04 @ 21:32
Thanks -- it now deploys on Heroku, but as you said it doesn't actually
appear to be achieving websocket-goodness. I've forwarded the issue to my
friend James who used to work there and I'll see what he says. Maybe they
can fix it.


-- Bruce Eckel
www.MindviewInc.com <http://www.mindviewinc.com/>
Blog: www.BruceEckel.github.io
www.WinterTechForum.com
www.AtomicScala.com
www.Reinventing-Business.com
www.ScalaSummit.com


On Wed, Mar 4, 2015 at 1:51 PM, Keyan Pishdadian <kpishdadian@gmail.com>
wrote:

> Hi Bruce,
>
> I just played around with that extension last week so I have some advice.
> The good news is you can add those arguments like you would when running
> the normal server:
>
> socketio.run(app, host=‘0.0.0.0’, port=port)
>
> The bad news is that Heroku is very weird about Socket.io. What ended up
> happening for me was that I could get two client browsers to interact but
> only if they accessed the server within a certain amount of time of each
> other. In general using Socket.io on Heroku is going to be no fun. I ended
> up switching to an AWS Ubuntu EC2 instance and it is running great. Get in
> touch if you want to talk about it some more.
>
> Good luck,
> Keyan
>
> On Mar 4, 2015, at 3:41 PM, Bruce Eckel <bruceteckel@gmail.com> wrote:
>
> I'm working on getting the example on this page:
> https://github.com/miguelgrinberg/Flask-SocketIO
>
> To work under Heroku. Here's my project so far:
> https://github.com/BruceEckel/hello-flask-websockets
>
> To get this to work, I can't call
>     app.run(host='0.0.0.0', port=port)
> directly, because the SocketIO object has to do it:
>     socketio.run(app)
>
> I've tried setting host and port like this:
>     app.config['host'] = '0.0.0.0'
>     app.config['port'] = int(os.environ.get("PORT", 5000))
>   ;   socketio.run(app)
>
> But to no avail.
>
> Thanks in advance.
>
> -- Bruce Eckel
> www.MindviewInc.com <http://www.mindviewinc.com/>
> Blog: www.BruceEckel.github.io <http://www.bruceeckel.github.io/>
> www.WinterTechForum.com <http://www.wintertechforum.com/>
> www.AtomicScala.com <http://www.atomicscala.com/>
> www.Reinventing-Business.com <http://www.reinventing-business.com/>
> www.ScalaSummit.com <http://www.scalasummit.com/>
>
>
>

Re: [flask] Need alternative way to set host and port

From:
Bruce Eckel
Date:
2015-03-05 @ 15:05
Here's the response I got from my friend. I don't understand everything so
I might end up waiting until he is back in town and then get some tutoring
from him on the project:

Socket.io works fine on Heroku, especially for single server deployments.
> The problem with Socket.io is that it is stateful on the server-side.  So
> if you want more than one node you will need to figure out how to propagate
> / distribute that state.  Some folks work around that by using sticky
> sessions (the wrong approach).
>
>
> The browser error when using https is:
> Mixed Content: The page at 'https://hello-flask-websockets.herokuapp.com/'
> was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint '
> http://hello-flask-websockets.herokuapp.com/socket.io/1/?t=1425506305296'.
> This request has been blocked; the content must be served over HTTPS.
>
> So you will have to match the protocol.
>
>
> When using http the websocket tries to connect but fails with:
> 500 Internal Server Error
>
> Server logs on this request:
>
> 2015-03-04T22:08:29.907514+00:00 app[web.1]:   File
> "/app/.heroku/python/lib/python2.7/site-packages/geventwebsocket/handler.py",
> line 88, in run_application
>
> 2015-03-04T22:08:29.909765+00:00 app[web.1]:  'HTTP_HOST': '
> hello-flask-websockets.herokuapp.com',
>
> 2015-03-04T22:08:29.909767+00:00 app[web.1]:  'HTTP_ORIGIN': '
> http://hello-flask-websockets.herokuapp.com',
>
> 2015-03-04T22:08:29.913001+00:00 heroku[router]: at=info method=GET path="/
> socket.io/1/websocket/223000998733" host=
> hello-flask-websockets.herokuapp.com 
request_id=4331b45a-fc4f-4bb5-8a11-89f7df97b721
> fwd="75.104.69.247" dyno=web.1 connect=1ms service=12ms status=500 bytes=161
>
> 2015-03-04T22:08:29.909786+00:00 app[web.1]:  'PATH_INFO': '/
> socket.io/1/websocket/223000998733',
>
> 2015-03-04T22:08:29.910272+00:00 app[web.1]:     websocket =
> self.handler.environ['wsgi.websocket']
>
> 2015-03-04T22:08:29.910279+00:00 app[web.1]: KeyError: 'wsgi.websocket'
>
> The fallback to polling is working fine though.
>
>
> I just remembered another way to get your app logs without using the
> command line.  Go to:
> https://addons.heroku.com/papertrail
>
> Add the free PaperTrail addon to your app.  Then you will get a nice web
> UI for your app logs.
>
>
> I hope that helps.
>


-- Bruce Eckel
www.MindviewInc.com <http://www.mindviewinc.com/>
Blog: BruceEckel.github.io
www.WinterTechForum.com
www.AtomicScala.com
www.Reinventing-Business.com
www.ScalaSummit.com


On Wed, Mar 4, 2015 at 1:51 PM, Keyan Pishdadian <kpishdadian@gmail.com>
wrote:

> Hi Bruce,
>
> I just played around with that extension last week so I have some advice.
> The good news is you can add those arguments like you would when running
> the normal server:
>
> socketio.run(app, host=‘0.0.0.0’, port=port)
>
> The bad news is that Heroku is very weird about Socket.io. What ended up
> happening for me was that I could get two client browsers to interact but
> only if they accessed the server within a certain amount of time of each
> other. In general using Socket.io on Heroku is going to be no fun. I ended
> up switching to an AWS Ubuntu EC2 instance and it is running great. Get in
> touch if you want to talk about it some more.
>
> Good luck,
> Keyan
>
> On Mar 4, 2015, at 3:41 PM, Bruce Eckel <bruceteckel@gmail.com> wrote:
>
> I'm working on getting the example on this page:
> https://github.com/miguelgrinberg/Flask-SocketIO
>
> To work under Heroku. Here's my project so far:
> https://github.com/BruceEckel/hello-flask-websockets
>
> To get this to work, I can't call
>     app.run(host='0.0.0.0', port=port)
> directly, because the SocketIO object has to do it:
>     socketio.run(app)
>
> I've tried setting host and port like this:
>     app.config['host'] = '0.0.0.0'
>     app.config['port'] = int(os.environ.get("PORT", 5000))
>   ;   socketio.run(app)
>
> But to no avail.
>
> Thanks in advance.
>
> -- Bruce Eckel
> www.MindviewInc.com <http://www.mindviewinc.com/>
> Blog: www.BruceEckel.github.io <http://www.bruceeckel.github.io/>
> www.WinterTechForum.com <http://www.wintertechforum.com/>
> www.AtomicScala.com <http://www.atomicscala.com/>
> www.Reinventing-Business.com <http://www.reinventing-business.com/>
> www.ScalaSummit.com <http://www.scalasummit.com/>
>
>
>