Heroku and Twisted

偶尔善良 提交于 2020-01-04 23:09:49

问题


I am trying to learn Twisted, a Python framework, and I want to put a basic application online that, when it receive a message sends it back. I decided to use Heroku to host it, and I followed the instructions on their docs.

import os
from twisted.internet import protocol, reactor

class Echo(protocol.Protocol):
    def dataReceived(self, data):
        self.transport.write(data)

class EchoFactory(protocol.Factory):
    def buildProtocol(self, addr):
        return Echo()

port = int(os.environ.get('PORT', 5000))
reactor.listenTCP(port, EchoFactory(), interface = '0.0.0.0')
reactor.run()

Its all working except (and I know this is a stupid question), how do I send a message to it? When I am working locally I just do telnet localhost <port>, but now I have no idea. Also, since heroku connects to a random port how can I know what port it connects my app to? Thanks.


回答1:


I'm not very familiar with Twisted, but I'm not sure what you're trying to do is supported on Heroku. Heroku currently only supports HTTP[S] requests and not raw TCP. There are more details in the answers to this question.

If you wanted to connect to your app, you should use the myapp.herokuapp.com host name or any custom domain that you've added.




回答2:


"Pure Python applications, such as headless processes and evented web frameworks like Twisted, are fully supported on Cedar."

Reference: https://devcenter.heroku.com/articles/python-support



来源:https://stackoverflow.com/questions/14525983/heroku-and-twisted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!