会有人了解Heroku并扭曲吗?
我在自己的电脑上测试了扭曲的代码
当客户端调用服务器时
服务器将消息返回给客户端
我的目的是将服务器放在heroku上,让客户端调用它并返回消息,不必使用网络。
当我将服务器代码移至Heroku时
如何启动server.py?
如何在client.py中设置ip?
我使用来自Getting Started on Heroku with Python
的git clone heroku官方代码下载我执行的步骤后
在requirements.txt
twisted == 1.6.0
在Procfile中增加worker: python server.py runserver 0.0.0.0: 5000
(server.py是扭曲的代码)
3。git push heroku master
worker: python manage.py runserver 0.0.0.0:5000
尝试过client.py中的connectTCP设置(" 0.0.0.0",5000,f),但没有回应
按下打开的应用程序会出现错误信息(但我没有使用网站....)
查看日志
at=error code=H14 desc="No web processes running" method=GET path="/" host=bitserver.herokuapp.com request_id=778e3bd2-310d-4d8d-aa75-737a1d89efdc fwd="220.130.40.2" dyno= connect= service= status=503 bytes=
server.py
from twisted.internet import protocol, reactor
import os
class Knock(protocol.Protocol):
def dataReceived(self, data):
print 'Client:', data
if data.startswith("Hey, Heroku!"):
response = "Hi, please wait..."
self.transport.write(response)
else:
response = "I don't know who you are!"
self.transport.write(response)
class KnockFactory(protocol.Factory):
def buildProtocol(self, addr):
return Knock()
reactor.listenTCP(5000, KnockFactory())
reactor.run()
client.py
from twisted.internet import protocol, reactor
class KnockClient(protocol.Protocol):
def connectionMade(self):
self.transport.write("Hey, Heroku!")
def dataReceived(self, data):
if data.startswith("Hi, please wait..."):
print ("Heroku:",data)
self.transport.loseConnection()
reactor.stop()
else:
print ("Heroku:",data)
self.transport.loseConnection()
reactor.stop()
class KnockFactory(protocol.ClientFactory):
protocol = KnockClient
def main():
f = KnockFactory()
reactor.connectTCP("0.0.0.0", 5000, f)
reactor.run()
if __name__ == '__main__':
main()
答案 0 :(得分:0)
我在其他论坛上得到了答案
Only web process types can receive connections, you'll need to setup any servers in the same way that you would with a web server, i.e., binging to 0.0.0.0:$PORT.